Page 1 of 1
How to get real-world output size from arbitrary input
Posted: 2010-07-15T11:06:42-07:00
by vepxistqaosani
I need to provide output files at 'real world' size, but the input files vary in resolution, geometry, and units.
That is, I could have 1700x1000 @ 120 pixels per centimeter and 1700x1000 @ 600 pixels per inch. I want output at 96 dpi, so the former should be 535x314 and the latter should be 272x160.
Is there anyway to accomplish this with a single ImageMagick command? Given the limits of my application, I cannot introspect the files before running convert.
Thanks!
Re: How to get real-world output size from arbitrary input
Posted: 2010-07-15T12:02:09-07:00
by snibgo
convert in.png -resample 96 out.png
Re: How to get real-world output size from arbitrary input
Posted: 2010-07-15T12:31:30-07:00
by vepxistqaosani
Thanks, but that only works for files with Units of PixelsPerInch.
Could it be that ImageMagick 6.5.9-2 2010-02-03 Q16 on Windows XP doesn't handle PixelsPerCentimeter correctly?
E.g.,
identify -verbose "Tall Thin.tif" | grep "Geometry\|Resolution\|Print\|Units"
Geometry: 1016x1306+0+0
Resolution: 120x120
Print size: 8.46667x10.8833
Units: PixelsPerCentimeter
convert "Tall Thin.tif" -resample 96 TallThin_096.jpg
identify -verbose "TallThin_096.jpg" | grep "Geometry\|Resolution\|Print\|Units"
Geometry: 813x1045+0+0
Resolution: 120x120
Print size: 6.775x8.70833
Units: PixelsPerCentimeter
Expected :: 255x328 @ 96
Re: How to get real-world output size from arbitrary input
Posted: 2010-07-15T12:32:08-07:00
by Drarakel
Use a "-units PixelsPerInch" option after reading the image, so that the former density value gets converted to inches first:
convert input -units PixelsPerInch -resample 96 output
(Note that in JPG files, you might need to strip some profiles afterwards if you want that the density info is displayed everywhere in the same way.)
Re: How to get real-world output size from arbitrary input
Posted: 2010-07-15T12:50:54-07:00
by vepxistqaosani
That sounds logical, but still doesn't work. I'm expecting the input size of 1016x1306 (at 120 PixelsPerCentimeter) to become 255x328 (at 96 PixelsPerInch).
An additional feature of the problem is that the same ImageMagick command has to handle PixelsPerInch inputs. Currently, I can handle inches but not centimeters.
So, the image is being scaled by 96/120, or 80%, even with the unit specifications and strip. Of course, I don't really care about the resolution, only the final size.
convert "Tall Thin.tif" -units PixelsPerInch -resample 96 -strip TallThin_096.jpg
identify -verbose "TallThin_096.jpg" | grep "Geometry\|Resolution\|Print\|Units"
Geometry: 813x1045+0+0
Resolution: 96x96
Print size: 8.46875x10.8854
Units: PixelsPerInch
convert "Tall Thin.tif" -units PixelsPerInch -resample 96 TallThin_096.jpg
identify -verbose "TallThin_096.jpg" | grep "Geometry\|Resolution\|Print\|Units"
Geometry: 813x1045+0+0
Resolution: 120x120
Print size: 6.775x8.70833
Units: PixelsPerCentimeter
Re: How to get real-world output size from arbitrary input
Posted: 2010-07-15T15:04:51-07:00
by snibgo
I'm expecting the input size of 1016x1306 (at 120 PixelsPerCentimeter) to become 255x328 (at 96 PixelsPerInch).
If my maths is correct: 1016 pixels at 120 PixelsPerCentimeter is 8.47cm or 3.33 inches. At 96 dpi, this is 320 pixels, not 255. Why do you expect 255?
Your IM is rather old. An upgrade may help.
Re: How to get real-world output size from arbitrary input
Posted: 2010-07-16T15:21:33-07:00
by Drarakel
I just saw the ImageMagick version. Yeah, updating is required.
In your older IM version, "-units PixelsPerInch" really only sets the units value. You have to use version 6.6.1-5 or newer - then that option converts the density before resampling starts.
(Of course you will still have problems if a false value is stored in the input file.

)
Re: How to get real-world output size from arbitrary input
Posted: 2010-07-19T11:04:29-07:00
by vepxistqaosani
An upgrade to 6.6.3 did solve the problem.
And, yes, my arithmetic was flawed. Sorry!
And thanks for the all the help.