Copy link to clipboard
Copied
I'm trying to save a Photoshop file, changing the width and height to 50%, the resolution to 300, and keeping transparency. If I save as .png, it flattens the layers.
Saving as "Save for Web" works, but for some reason, it is changing the resolution to 72 and the width to 37in. If I open the image in Photoshop and change the resolution to 300, I get the correct width of 8.88in.
Here is what I have in the script. I'm new to javascript so bear with me.
var xMaxFullDimension=activeDocument.width.as('in'); | ||
var yMaxFullDimension=activeDocument.height.as('in'); | ||
activeDocument.resizeImage(new UnitValue(xMaxFullDimension*50/100,'in'), new UnitValue(yMaxFullDimension*50/100,'in'), 300, ResampleMethod.BICUBIC); |
sfwPNG24(saveFile,100); | |
function sfwPNG24(saveFile,quality){
var pngOpts = new ExportOptionsSaveForWeb;
pngOpts.format = SaveDocumentType.PNG;
pngOpts.PNG8 = false;
pngOpts.transparency = true;
pngOpts.interlaced = false;
pngOpts.resolution=300;
pngOpts.quality = quality;
activeDocument.exportDocument(new File(saveFile),ExportType.SAVEFORWEB,pngOpts);
}
You can use just a normal save as rather than save for web to keep the 300 dpi. You can use scriptlistener to record all the code.
Copy link to clipboard
Copied
Since this is save for web, the default web dpi is 72, so it changes the file to that, adjusting the length in inches. The pixel res remains the same. I'm not sure there is anything you can do.
Copy link to clipboard
Copied
You can use just a normal save as rather than save for web to keep the 300 dpi. You can use scriptlistener to record all the code.
Copy link to clipboard
Copied
saveAs works like in Photoshop UI, ie. converts open document to new fileformat (which for PNG means flattening layers). But you can just duplicate the original doc and use saveAs on that and close it.
var tmp = original.duplicate("export_tmp")
tmp.saveAs(saveFile, pngOpts, false, Extension.NONE)
tmp.close(SaveOptions.DONOTSAVECHANGES)
Copy link to clipboard
Copied
Chuck, I had tried just using the save function but it was flattening the file. I used the scriptListener and that solved my problem.
Matias, I tried your approach but it paused to ask for the file name. This is a batch process that is converting hundreds of covers.
Copy link to clipboard
Copied
Add app.displayDialogs = DialogModes.NO
Copy link to clipboard
Copied
Thanks.