Using a formula for the value of -density
Posted: 2011-02-02T07:32:41-07:00
Is there any way to give -density a formula instead of a fixed value?
I am trying to convert a PDF to JPEG by rendering with at 2x the intended output density, downsampling to get antialiased lines, and finally assigning the output JPG proper density (ppi) metadata so that its physical size in inches is the same as the original PDF (even if ppi is different).
Taking into accound Imagemagick considers all PDFs to be 72 ppi, consider this example:
The input file is first rendered with a density (288) twice the intended output density for better antialiasing. Output density (144) is then added to the output file to preserve physical size in inches:
Hence, if using a formula, I was thinking of something like:
But apparently -density does not accept that kind of fx formulas. Any way to do it then?
I am trying to convert a PDF to JPEG by rendering with at 2x the intended output density, downsampling to get antialiased lines, and finally assigning the output JPG proper density (ppi) metadata so that its physical size in inches is the same as the original PDF (even if ppi is different).
Taking into accound Imagemagick considers all PDFs to be 72 ppi, consider this example:
- The input PDF is 10x10 inches, i.e. 720x720px at 72 ppi
- The output JPG should be 1440x1440px at 144ppi
Code: Select all
convert -density 288x -geometry 1440x input.pdf -density 144x output.jpg
Code: Select all
144 = output size in px / (input width in px / original dpi) = 1440 / (720 / 72)
Code: Select all
convert -density "%[fx:round(2*(1440/(w/resolution.x)))"x -geometry 1440x input.pdf -density "%[fx:round((1440/(w/resolution.x)))"x output.jpg