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

how to convert pixels in mm ?

Participant ,
Jul 21, 2013 Jul 21, 2013

Hello everybody!

I'm making a tool in which the user specifies the size of the frame, I want to give him the opportunity to choose between units of measurement. How do I convert one unit to another? Centimeters to millimeters as I know 🙂

The calculations in my instrument produced in pixels. A user wants to place on a sheet of paper photos of a certain size in order to then cut them after printing and pasted into the frame.

This part of the script produces the  selection of the pixel size, but calculation was conducted in millimeters.

app.preferences.rulerUnits = Units.MM;



var newSelect = Array(

                   Array(Left, Top),

                   Array(Right, Top),

                   Array(Right, Bottom),

                   Array(Left, Bottom),

                   Array(Left, Top)

);

doc.selection.select(newSelect);

Came up with a solution, I do not know how much it is optimal - use factor

app.preferences.rulerUnits = Units.MM;

rmm = doc.width;

app.preferences.rulerUnits = Units.PIXELS;

rpix = doc.width;

var propPixMm = rpix.value/rmm.value;

TOPICS
Actions and scripting
50.5K
Translate
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
Adobe
Community Expert ,
Jul 22, 2013 Jul 22, 2013

Pixels are not physical units of measurement. They are computer data units that define a raster image.

You can have 1000 pixels and decide whether they print to 1 mm, 1 cm, or 1 meter in length. It will still be 1000 pixels.

The best way to see this is to open a file, open the Image Size box and turn resampling off.

Change the physical size and you will see the amount of pixels remain the same.

Translate
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
Participant ,
Jul 22, 2013 Jul 22, 2013

My last solution is used Photoshop patameters and Photoshop factor, I'm happy ^-)

Translate
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
Contributor ,
Jul 22, 2013 Jul 22, 2013

Resolution is what connects pixels with real world. Printing standard of resolution is 300ppi, that means the 'density' of pixels is 300 pixels per inch.

Translate
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
Guru ,
Jul 22, 2013 Jul 22, 2013

When using UnitValue objects you can have it convert between unit types.

app.preferences.rulerUnits = Units.MM;// or any other unit except percent

var rmm = doc.width;

alert(rmm.as('px'));

Translate
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
Participant ,
Jul 22, 2013 Jul 22, 2013

my variant (all correct):

#target photoshop

var doc = app.activeDocument ;

app.preferences.rulerUnits = Units.MM;

rmmW = doc.width.value;

app.preferences.rulerUnits = Units.PIXELS;

rpixW = doc.width.value;

var PixMm = rpixW/rmmW;

alert(rmmW +"mm / "+rpixW +"pix\n factor " + PixMm);

p2.pngp3.png

Translate
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 ,
Jul 22, 2013 Jul 22, 2013

var doc = app.activeDocument;

app.preferences.rulerUnits = Units.MM;

rmmW = doc.width.value;

app.preferences.rulerUnits = Units.PIXELS;

rpixW = doc.width.value;

var PixMm = rpixW/rmmW;

// 🙂

var WidthMM= rpixW/doc.resolution*25.4;

alert(rmmW +"mm / "+rpixW +"pix\n factor " + PixMm);

// 🙂

alert(doc.resolution+"\n"+WidthMM+" mm");

Translate
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 ,
Jul 24, 2013 Jul 24, 2013

@Andy_Bat1,

Did you found the best solution for you?

Translate
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
Participant ,
Jul 31, 2013 Jul 31, 2013

I'm stopped on my self solution

Translate
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
Guru ,
Jul 22, 2013 Jul 22, 2013

Sorry, I was not trying to say your variant does not work. I was just pointing out how to use less code and take advantage of the UnitValue method.

Translate
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
New Here ,
Feb 15, 2016 Feb 15, 2016
LATEST

How to Convert from Pixels to Millimeters from How to convert from pixels to millimeters « DallinJones.com

In chemistry, we studied something called dimensional analysis. Dimensional analysis is a method for converting from one unit to another. So first off we multiply the number of pixels by 1 over our DPI (in this case 300 DPI) then we multiply that by 25.4 by one inch (number of millimeters in an inch) Once everything cancels out we are left with a fairly nice, simple and easy to use formula.

mm = (pixels * 25.4) / dpi

In order to convert back from millimeters to pixels we simply reverse the formula using simple algebra.

pixels = (mm * dpi) / 25.4

There you have it. A very simple way to convert from pixels to millimeters. And then from millimeters back to pixels.

Translate
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