The $image->Get( 'y-resolution' ) returns the number of pixels. Think of them as the ‘dots’ in <acronym title="Dots Per Inch">DPI</acronym>.

To determine the printable size from this without rescaling, you’d divide by the DPI to get the size in inches. I’ll leave the imperial -> metric conversions to you.

If you plan to resample an image ‘to-fit’ what you’d want is to determine the factor by which to resize. To do this you’d take the maximum paper size times the dpi, then divide by the image size.

use constant PAGE_WIDTH => 8; # 8.5" page with 0.5" of equal margins. use constant DPI => 72; # Fax resolution. # ... $scale_factor = ( PAGE_WIDTH * DPI ) / $image->Get( 'y-resolution'); # ...

The above however doesn't take into acount which dimension we need to fit to scale. If you want to maintain the aspect ratio you’d need to figure out which dimension to scale to, easiest would be to figure out both and take the min. factor.

You could also choose to switch orientation so that the highest pixel count always went along the longest page dimension.

Note:

8.5" x 11" is not A4 , it’s letter. I just used those dimensions for convenience. As for faxes, I think they can be 150DPI as well, but it would pay to check.


In reply to Re: PerlMagick: How to Calculate an image size in milimiters? by Arguile
in thread PerlMagick: How to Calculate an image size in milimiters? by monsieur_champs

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.