Skip to main content
Leilang
Inspiring
February 12, 2019
Question

Convert PX to CM

  • February 12, 2019
  • 1 reply
  • 7307 views

Quick question

How convert PX to CM ?

var doc = activeDocument;

var artLayer = activeDocument.activeLayer;

var textItem = artLayer.textItem;

textItem.kind = TextType.PARAGRAPHTEXT;

var textWidth = textItem.width.as("px");

var textHeight = textItem.height.as("px");

alert(textWidth+"_"+textHeight);

textItem.width.as("cm");  ----> It does not show the correct value and the value is different depending on the resolution.

;

This topic has been closed for replies.

1 reply

Chuck Uebele
Community Expert
Community Expert
February 12, 2019

I believe you need to set the units for everything to what ever you want to use:

app.preferences.rulerUnits = Units.PIXELS;

Leilang
LeilangAuthor
Inspiring
February 12, 2019

I found a solution

var LB = activeDocument.activeLayer.bounds;

var width = LB[2].as("cm") - LB[0].as("cm");

alert(width);

Leilang
LeilangAuthor
Inspiring
February 12, 2019

Leilang 

I found a solution

This is not true.
Just like almost always lying textItem.width and textItem.height


My point was that I found a way to solve my problem differently.

I wanted to know the width of the text in centimeters and now I know.

If I mislead you, I apologize;) Of course, textItem.width is still useless.