Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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.


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.

Replies are listed 'Best First'.
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.

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://262808]
[ambrus]: Corion: as for that, I talked with schmorp, and looked a bit more at Prima
[ambrus]: Corion: from the docs, it definitely looks like it would be possible to write an AnyEvent driver for it using Prima::File and Prima::Timer.
[ambrus]: (I haven't found an idle event.)
[ambrus]: However, I also looked at the internals, and found two interesting things:
[marto]: stupid xpath question, I have a xpath copied from the browser, is the * wildcard supposed to work for IDs? e.g. '//*[@id="*"]/ div/div/header/p/a '?
[ambrus]: The main loop for unixish systems is in https://metacpan. org/source/ KARASIK/Prima-1. 49/unix/apc_app.c. It is a hand-rolled select loop, but also always spins at least once every 0.2 seconds for some reason.

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (8)
As of 2016-12-08 10:48 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (140 votes). Check out past polls.