Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: PerlMagick: How to Calculate an image size in milimiters?

by Arguile (Hermit)
on Jun 03, 2003 at 21:53 UTC ( #262808=note: print w/ replies, xml ) Need Help??


in reply to PerlMagick: How to Calculate an image size in milimiters?

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.


Comment on Re: PerlMagick: How to Calculate an image size in milimiters?
Select or Download Code
Re: Re: PerlMagick: How to Calculate an image size in milimiters?
by Cody Pendant (Prior) on Jun 03, 2003 at 23:51 UTC
    >As for faxes, I think they can be 150DPI as well, >but it would pay to check.

    I'd really like to know the answer to that as well -- I had a rather bizarre incident the other day in which a colleague wanted to fax the drawn outline of his foot to a specialist bootmaker in Poland.

    As just a few mils either way could make all the difference to an item of footwear, I advised him not to -- who knows what actual size it's going to come out the other end?

    Presumably faxes have some kind of handshaking process where they try and establish what DPI they can both safely use? And what's the margin of error allowed in the standard?
    --

    “Every bit of code is either naturally related to the problem at hand, or else it's an accidental side effect of the fact that you happened to solve the problem using a digital computer.”
    M-J D
Re: Re: PerlMagick: How to Calculate an image size in milimiters?
by ehdonhon (Curate) on Jun 04, 2003 at 00:55 UTC

    Faxes use the CCITT Group 3 protocol. They support 2 resolutions: 203 by 98 dpi and 203 by 196 dpi. So, the code you listed will need to be modified slightly to accommodate different resolutions in the x and y axis. Here is a detailed description of the fax protocol.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://262808]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2014-07-26 11:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (176 votes), past polls