Skip to main content
d_stoeck
Participating Frequently
June 17, 2013
質問

How to "change" resolution from DPI to l/cm?

  • June 17, 2013
  • 返信数 2.
  • 5975 ビュー

Hi Adobe community,

right now I am transferring a huge and slow photoshop action to a javascript cause I needed some kind of dynamic variable an action couldn't offer. And on the other hand: a script is sooo much faster than an action. I had some points where the scripting API didn't give me enough possibilities and I had to use those annoying "action descriptors" I got from the ScriptingListener Plugin... so far so good.

But now I am at a point where neither the API nor action descriptors seem to help. I am trying to switch the resolution of the image from "dots per image" to "lines per cm" without really resampling it. I just want to transform the "measurement unit", for example from 304.8 DPI to 120 l/cm or from 72 DPI to 28.346 l/cm.

Does anyone know a way how to do this? Obviously it is possible through manual usage of the "image size" menu. And yes, I am aware of the fact that this is just cosmetic. But the client that needs this script sort of insists of the "lines per cm" measurement unit.

I would really appreciate any help.

Greetings,

Daniel

このトピックへの返信は締め切られました。

返信数 2

d_stoeck
d_stoeck作成者
Participating Frequently
June 19, 2013

Can anybody help? Did anybody face the same problem already?

I mean... what I want is fairly easy if u do it via the Photoshop menu... but via javascript it just doesn't want to work :-/

Inspiring
June 19, 2013

I now think that you are tying to set the resolution unit dropdown in the Resize Image dialog. That is a dialog preference and I don't know of a way to change that with a script.

Inspiring
August 15, 2013

Michael, thank you very much for your code. I tried it and played around with it. It kinda works... the file itself gets modified and when I inspect the metadata of the image, I see all the values I changed. Especially ResolutionUnit = 3...

...but when I reopen the image in Photoshop, it still has the old values. Photoshop seems to ignore the changes.

See this screenshot of the metadata information: (the old value of ResolutionUnit actually was 2... just dont have a screenshot of that right now)

and compare it with the information in the "resize image dialog":

These are the complete metadata Photoshop shows me...

... where the hell does Photoshop get the "wrong & old" information seen in the 2nd screenshot? Any ideas? :-/

Regards,

Daniel


It seems that if you save the document for Save For Web, then apply the metadata, it seems to work. As an example create a docment and run the following code.

var f = File(Folder.desktop + "/300PPI.jpg");

SaveForWeb(f,60);

app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

setRes(f,300);

open(f);

function setRes( file, newRes ){

if ( !ExternalObject.AdobeXMPScript ) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');

        var xmpf = new XMPFile( File(file).fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE );

        var xmp = xmpf.getXMP();

        xmp.deleteProperty( XMPConst.NS_TIFF, 'XResolution');

        xmp.setProperty( XMPConst.NS_TIFF, 'XResolution', newRes+"/1");

                xmp.deleteProperty( XMPConst.NS_TIFF, 'YResolution');

         xmp.setProperty( XMPConst.NS_TIFF, 'YResolution', newRes+"/1");

          var PerInch = xmp.setProperty( XMPConst.NS_TIFF, 'ResolutionUnit',3); //Pixels per cm

      if (xmpf.canPutXMP( xmp )) {

         xmpf.putXMP( xmp );

      }

      xmpf.closeFile( XMPConst.CLOSE_UPDATE_SAFELY );

}

function SaveForWeb(saveFile,jpegQuality) {

var sfwOptions = new ExportOptionsSaveForWeb();

   sfwOptions.format = SaveDocumentType.JPEG;

   sfwOptions.includeProfile = false;

   sfwOptions.interlaced = 0;

   sfwOptions.optimized = true;

   sfwOptions.quality = jpegQuality;

activeDocument.exportDocument(saveFile, ExportType.SAVEFORWEB, sfwOptions);

}

Inspiring
June 17, 2013

In Photoshop 'dots' or 'lines' means pixels. DPI normally means dots per inch( or pixels per inch ). So it sounds to me like all you need to do is change the resolution from inches to cm. That can be done with imageResize().

d_stoeck
d_stoeck作成者
Participating Frequently
June 17, 2013

the API says:

resizeImage([width] [, height] [, resolution] [, resampleMethod])

width is a UnitValue

height is a UnitValue

resolution is a number

resampleMethod is from type ResampleMethod

I might be wrong, but I don't see the possibility here to change from inches to cm cause resolution is just a number? :-/

taken from: here

Inspiring
June 17, 2013

Maybe I mis-understood your question. Yes the resoluton arugment is pixels. So when the ppi doesn't match the ppcm you do the math to resize the image. If the ppi = 72 then ppcm = 28.346. It's just a matter of what ruler you use.