1
votes

When I save a PNG-24 file using (manually) Photoshop I get this image (15.5KB):

enter image description here

When saving using javascript I get this image (14.1KB):

enter image description here

The source image is a square 512 pixels that I resize to 96 pixels (manually in the first case, and by script in the second case)

The script in question is:

// options to use on export
var options = new ExportOptionsSaveForWeb();
options.quality = 100;  
options.format = SaveDocumentType.PNG;  
options.PNG8 = false;

// resize
doc.resizeImage(UnitValue(96,'px'), null, null, ResampleMethod.BICUBIC);
// save to file
var newname = doc.fullName + '_96.png';
newname = newname.replace ('.psd', '');
doc.exportDocument(new File(newname), ExportType.SAVEFORWEB, options);

Anybody can tell me what are the right options to use to get the same image using the script?

1
Maybe a stupid remark, but are you sure you are using the same image? This shadow in lower right corner doesn't look even similar in two images you posted. And for the options... It depends on your Photoshop Save For Web settings. - Zemljoradnik
@Zemljoradnik Yes, it is the same source image. And regarding the second comment, that's what my question is all about, I cannot pinpoint the difference in options, if I could, I would not have asked. - ilomambo

1 Answers

1
votes

Well, I found a very informative post, how to record a Photoshop action and look at the js or vb file of it.
You need to use a plug-in called Script Listener, you can download it from the Adobe Scripting Page

Follow the instructions in this post (not the accepted answer, but the answer by Kevin Sharnhorst)

Then it is easy to compare the action to the script I have, worst case I can use the code created by the listener to execute the exact same action.

Edit after real run After using the aforementioned technique the culprit was not the SaveForWeb function, but the image resize. Seems to be there are not enough options in the doc.resizeImage() to achieve the same result.
I copied the listener (ugly) code instead, and now the results are the same as expected

var idImgS = charIDToTypeID( "ImgS" );
    var desc2 = new ActionDescriptor();
    var idWdth = charIDToTypeID( "Wdth" );
    var idPxl = charIDToTypeID( "#Pxl" );
    desc2.putUnitDouble( idWdth, idPxl, 96.000000 );
    var idscaleStyles = stringIDToTypeID( "scaleStyles" );
    desc2.putBoolean( idscaleStyles, true );
    var idCnsP = charIDToTypeID( "CnsP" );
    desc2.putBoolean( idCnsP, true );
    var idIntr = charIDToTypeID( "Intr" );
    var idIntp = charIDToTypeID( "Intp" );
    var idbicubicAutomatic = stringIDToTypeID( "bicubicAutomatic" );
    desc2.putEnumerated( idIntr, idIntp, idbicubicAutomatic );
executeAction( idImgS, desc2, DialogModes.NO );