Hi Stephen Marsh
I don't know much about it. Please enlighten me.
Thank you very much.
Hi Stephen Marsh
I don't know much about it. Please enlighten me.
Thank you very much.
By @dublove
Sure, the previous code created 2 history steps:
1) Image Size (72 ppi)
2) Image Size (original ppi value)
So if one clicked on the first history step, then the document resolution would no longer be correct.
Multiple history steps can be combined into a single entry in the history panel by calling the setZoom(100) function and parameter using suspendHistory()
// Call the zoom function from within suspendHistory
activeDocument.suspendHistory("Set Zoom to 100%", "setZoom(100)");
// Open the image size dialog
sTID = function (s) { return app.stringIDToTypeID(s); };
try {
executeAction(sTID('imageSize'), undefined, DialogModes.ALL);
} catch (e) { if (e.number != 8007) { alert("Line: " + e.line + "\n\n" + e, "Bug!", true); throw (e); } }
function setZoom(zoom) {
var docRes = activeDocument.resolution;
try {
cTID = function (s) { return app.charIDToTypeID(s); };
activeDocument.resizeImage(undefined, undefined, 72 / (zoom / 100), ResampleMethod.NONE);
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated(cTID("Mn "), cTID("MnIt"), cTID('PrnS'));
desc.putReference(cTID("null"), ref);
executeAction(cTID("slct"), desc, DialogModes.NO);
activeDocument.resizeImage(undefined, undefined, docRes, ResampleMethod.NONE);
} catch (error) {
if (docRes !== undefined) {
activeDocument.resolution = docRes;
}
alert("Line: " + (error.line || 'unknown') + "\n\n" + error.message, "Bug!", true);
throw error; // Optional to abort the script
}
}
I have also added error checking in the setZoom() function to restore the original document resolution if an unexpected error occurs.