Page 1 of 1
density based on size
Posted: 2015-09-29T17:53:38-07:00
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
Re: density based on size
Posted: 2015-09-29T18:48:38-07:00
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
Re: density based on size
Posted: 2015-10-01T06:33:11-07:00
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.
Re: density based on size
Posted: 2015-10-01T08:45:18-07:00
by fmw42
Re: density based on size
Posted: 2015-10-01T15:35:29-07:00
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.
Re: density based on size
Posted: 2015-10-01T16:13:56-07:00
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.
Re: density based on size
Posted: 2015-10-01T16:34:58-07:00
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.