density based on size

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Lars-Daniel
Posts: 37
Joined: 2015-09-20T05:55:17-07:00
Authentication code: 1151

density based on size

Post by Lars-Daniel »

Hi there,

is there a way to choose the resolution (ppi) based on the final size in millimeters?

Right now, I'm using a script like this to get 550 x 550 mm output (the image is 4300 x 4300 px) :

Code: Select all

echo (4300*2.54/55) | tr -d $'\r' | bc -l
= 198.58181818181818181818

Code: Select all

convert -density 198.58181818181818181818 -units PixelsPerInch input.tif output.jpg
exiftool -XResolution=198.58181818181818181818 -YResolution=198.58181818181818181818 output.jpg
Would be more easy to use -extent in millimeters. Is this possible?

Best,
Lars-Daniel
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: density based on size

Post by fmw42 »

I do not see why you would want to use -extent. It does not set print density. It only pads or crops the image to the specified size. It does not allow mm units only pixels or percent.

This is how I would do it using IM's fx calculator and saving as a variable. Proper IM syntax has the input raster image right after convert, though in this case it really does not matter, since all your arguments are settings and not operators.

Code: Select all

size=4500
mm=55
dens=$(convert xc: -format "%[fx:2.54*$size/$mm]" info:)
convert input.tif -density $dens -units PixelsPerInch output.jpg
Lars-Daniel
Posts: 37
Joined: 2015-09-20T05:55:17-07:00
Authentication code: 1151

Re: density based on size

Post by Lars-Daniel »

It would be nice to let IM do the change of the density automatically based on printing size the user gives it it. This would help Windows users.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: density based on size

Post by fmw42 »

Lars-Daniel
Posts: 37
Joined: 2015-09-20T05:55:17-07:00
Authentication code: 1151

Re: density based on size

Post by Lars-Daniel »

That's the point: I do NOT want to resample it. Only density should change, image dimensions (pixels) shouldn't change.

Let's say the image is 1000 x 1000 px and has 300 ppi by design; this would mean 84,67 x 84,67 mm when printed 1:1.
I'd love to have a function like this: convert -resample 50x50mm -density only <input> <output>

Then the image's density should be changed to 508 ppi without any resizing.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: density based on size

Post by fmw42 »

Post your request to the Developers forum for a new function. I do not think you can supply mm on -resample and -density "only" would need to be a -define rather than a -density option. Proper IM 6 syntax has the input image right after convert for raster images.

So it could be something like:

Code: Select all

convert image -units pixelsperinch \
-define:resample:density=only -define:resample:units=mm \
-resample 50x50 output
Perhaps the second define is enough and the first would be implied by the second?

Or better, just a new function such as -setdensity 50mm, e.g.

Code: Select all

convert image -setdensity=WxH+[mm,cm,in] output
In any case, this would convert your 50 mm print size to a density for the appropriate units and pixel dimensions.

But let the IM developers decide what is best. Perhaps they have a better way.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: density based on size

Post by snibgo »

"-resample" curently does two things: it resizes, and it changes the metadata density setting. As there is already an operator devoted solely to changing the density setting, it would be perverse to change "-resample" so that it, too, could merely change the density.

The units for the required operator are units of length (inches, mm or whatever) so creating this as a new operator makes more sense than shoe-horning an existing operator.

IM is open source. Perhaps the OP could do this himself.
snibgo's IM pages: im.snibgo.com
Post Reply