Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Dear all,

use Image::Magick;
$imgobj =Image::Magick->new();
$x=$imgobj->ReadImage($ARGV[0]);
$width = $imgobj->Get('width');   #in Pixels
$height = $imgobj->Get('height'); #in Pixels 

How can i convert these values from Pixels to Millimeters

 - Ayyappan
  • Comment on Conversion Modules from Pixels to Millimeters

Replies are listed 'Best First'.
Re: Conversion Modules from Pixels to Millimeters
by PodMaster (Abbot) on Apr 16, 2004 at 06:25 UTC
    Do you know what a pixel is?
    --- [from wn] --- pixel n : (computer science) the smallest discrete component of an image or picture on a CRT screen (usually a colored dot); "the greater the number of pixels per inch the greater the resolution" [syn: {pel}, {picture element}]
    So to translate pixels to millimeters you first have to know your resolution. I hear most common resolution is 72 pixels per inch.

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

Re: Conversion Modules from Pixels to Millimeters
by matija (Priest) on Apr 16, 2004 at 06:28 UTC
    You can't - until you know where that picture is going to be used. It depends on DPI (dots per inch) of the output device.

    Is it going to be displayed on a monitor? Then it might be 100 DPI or 75 DPI (those two values are usualy used for the sizing of fonts) or if the user has played with the monitor resolution, it might be some random number. (But generaly in that range).

    If the image is going to be printed, that is usualy a much higher DPI than the monitor - 300 and up. High quality linotype printers generaly start at 2500 DPI.

      On X11 systems, you can filter out the dpi number with the xdpyinfo command. On my system I get:
      screen #0: dimensions: 1280x1024 pixels (361x292 millimeters) resolution: 90x89 dots per inch

      If you have Tk available on your system, you can get the dpi number by using the screenheight, screenmmheight, screenwidth and screenmmwidth methods. See also the Tk::Widget documentation.

        That can only ever be a guess. It assumes that the system is set up properly, which is just crazy talk.