• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How do we get the Pixel/Centimeter information ImageSize window [through Javascript]

Explorer ,
Jun 22, 2021 Jun 22, 2021

Copy link to clipboard

Copied

Hi Everyone!,

Is this possible to get Pixel/Centimeter information ImageSize window through JavaScript?

Thank in Advance

 

mbz85703520_0-1624354881642.png

 

TOPICS
Actions and scripting , Windows

Views

2.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

People's Champ , Jun 22, 2021 Jun 22, 2021

You can do it like this

 

 

//activeDocument.save(); // must be saved to force update metadata 

var xmp = new XML(activeDocument.xmpMetadata.rawData);  
var s = String(eval("xmp.*::RDF.*::Description.*::ResolutionUnit"));  

if (s == "3") alert("cm")
if (s == "2") alert("inch")

 

upd. I don't seem to understand again. I am groot .... : )

 

Votes

Translate

Translate
Adobe
LEGEND ,
Jun 22, 2021 Jun 22, 2021

Copy link to clipboard

Copied

activeDocument.resolution / 2.54

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 22, 2021 Jun 22, 2021

Copy link to clipboard

Copied

Curious minds need to know...

 

Photoshop image size truncates the display to 3 decimal places for a 240 PPI doc:

 

From: 94.488188976378 PPCM

To: 94.488 PPCM

 

 

var docResCM = app.activeDocument.resolution / 2.54;
var docResFixed = docResCM.toFixed(3);
var docResRounded = Math.round(docResCM * 1000) / 1000;
alert(docResCM + "\r" + docResFixed + "\r" + docResRounded);

 

 

The code above results in 94.488

 

However - Math.trunc(n) is not supported if I understand things correctly to easily chop off after (3).

 

Surely there must be a better way to truncate to 3 places than to transform the number into a string, regex remove all digits after the dot + 3 places, and then possibly return the string to a number if the end use requires a number for further calculations?

 

P.S. In the screenshot above, the truncation is to 2 decimal places, however, mine truncates to 3?

118.110236220472441

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 22, 2021 Jun 22, 2021

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Jun 22, 2021 Jun 22, 2021

Copy link to clipboard

Copied

You can do it like this

 

 

//activeDocument.save(); // must be saved to force update metadata 

var xmp = new XML(activeDocument.xmpMetadata.rawData);  
var s = String(eval("xmp.*::RDF.*::Description.*::ResolutionUnit"));  

if (s == "3") alert("cm")
if (s == "2") alert("inch")

 

upd. I don't seem to understand again. I am groot .... : )

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 22, 2021 Jun 22, 2021

Copy link to clipboard

Copied

Hi R-bin,

Thank you for the prompt response. It's working like a charm.

Is this possible to change Pixel/Centimeter to Pixel/Inch using java script?

 

-yajiv

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 22, 2021 Jun 22, 2021

Copy link to clipboard

Copied

I'm not r-bin, so I'm not sure if this is out of context or if I am misunderstanding... Multiplication is the opposite of division. So swap / 2.54 for * 2.54

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 22, 2021 Jun 22, 2021

Copy link to clipboard

Copied

That's question to r-bin. Btw, why are you littering this thread?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 22, 2021 Jun 22, 2021

Copy link to clipboard

Copied

Littering? Contributing? Learning? Disenchanted?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 22, 2021 Jun 22, 2021

Copy link to clipboard

Copied

What do you mean by your post?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 22, 2021 Jun 22, 2021

Copy link to clipboard

Copied

Hi Kukurykus,

I'm not doing like that Btw, I have collected different types of altrenate solutions for the same question/thread.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 22, 2021 Jun 22, 2021

Copy link to clipboard

Copied

Yes, you do. You posted the same content over here within 10 minutes.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 22, 2021 Jun 22, 2021

Copy link to clipboard

Copied

Hi Kukurykus,

At this time I'm facing a network issue and I really don't know whether the first post was upload or not.

For this reason,  again I repost that it. If you think I make this thread Littering.

Sorry for the inconvenience.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 22, 2021 Jun 22, 2021

Copy link to clipboard

Copied

 

XML(activeDocument.xmpMetadata.rawData)
['rdf:RDF']['rdf:Description']['tiff:ResolutionUnit']

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 22, 2021 Jun 22, 2021

Copy link to clipboard

Copied

Hi Kukurykus,
Thank you for your prompt response.

Is this possible to change Px/Cm to Px/In via JavaScript?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 22, 2021 Jun 22, 2021

Copy link to clipboard

Copied

Hi R-bin,

Thank you for the prompt response. It's working like a charm.

Is this possible to change Pixel/Centimeter to Pixel/Inch using java script?

 

-yajiv

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Jun 22, 2021 Jun 22, 2021

Copy link to clipboard

Copied

I dont know.

 

You can try the following.

1. Select all

2. Run the copy command

3. Create a new document from the clipboard (will be in inches)

4. Select and copy all layers into a new document.

5. Remove the old layer.

6. Close the original document.

7. Save the new document over the old one.

 

Code can be obtained using the ScriptListener plugin.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 22, 2021 Jun 22, 2021

Copy link to clipboard

Copied

Hi R-bin,

Thank you for your suggestion.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 23, 2021 Jun 23, 2021

Copy link to clipboard

Copied

You may try also this code handling .psd files probably up to 500 MB:

 

re = /(8BIM\x03\u00ED\x00\x00\x00\x00\x00\x10)(?:((?:[^\n]|[\n]){5})((?:[^\n]|[\n]))((?:[^\n]|[\n]){2})){2}/
preferences.autoUpdateOpenDocuments = true, (fle = activeDocument.fullName).open('r'), fle.encoding = 'binary'
r = (fle.read()).replace(re , function(_, v2, v3, _, v5) {return v2 + (end = v3 + '\x01' + v5) + end}), fle.open('w')
fle.write(r); (documents.add(uv = UnitValue('1 px'), uv, 1)).close(SaveOptions.DONOTSAVECHANGES)

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Jun 23, 2021 Jun 23, 2021

Copy link to clipboard

Copied

Not sure if this is a good idea. As a result, I got a file in which ImageSize shows inches, and EXIF and XMP show centimeters.

 

upd.

I think it will be more reliable to make a clicker.

Sequence needs to be sent: ctrl+alt+i, alt+r, tab, up, enter.

 

upd2

Question. Why create and close a document?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 23, 2021 Jun 23, 2021

Copy link to clipboard

Copied

LATEST

Yes, it only rewrites 2 instances of same value. The metadata could be also updated by script or just cleared 🙂 The combinations of self pressed keys by for example vbscript is an idea too. The need of creating new document is to change focus from the document to other one that is automaticaly closed. Thanks to it the ResolutionUnit is updated.

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines