Search code examples
graphicsphotoshopphotoshop-script

Photoshop Script Resize Image, does not update the resolution


I have an image when manually resized to width 1000pts the resolution comes to 261.5pixels/inch

Original Image Dimensions

enter image description here

Manual Update width to 1000pts

enter image description here

The resolution downgraded to 261.5 px/in

When i try the same programmatically with js script the width changes but resolution is same as of the original image

JS Code

 document.resizeImage(UnitValue(parseInt(row.width),"pt"), null, null); //working

where row.width = 1000

Image dimensions after executing the js script

enter image description here

How to calculate the resolution of the image automatically and set to 261.5px/inch


Solution

  • The new resolution should be manually calculated.

    newResolution = document.resolution * (originalWidth / parseInt(row.width));
    document.resizeImage(null, null, newResolution, ResampleMethod.NONE);
    document.resizeImage(UnitValue(parseInt(row.width), "pt"), null, null); 
    

    If the width is changed, the height will be changed programatically, which caused an impression, ResampleMethod.NONE will set the resolution too.