Yair Zaslavsky
Yair Zaslavsky

Reputation: 4137

Usage of -density switch with the do not enlarge flag for -resize does not work


I am working on a feature of an image conversion service, and I need to scale an image -
if the requested dimensions are bigger of the original image, it should not enrlage.
ImageMagick supports that,
but when I use -density to improve quality of converted image (I convert from pdf to png) , the "do not enlarge" behavior does not work well.


examples:

Image attributes for /home/yzaslavs/Downloads/drawing.pdf
/home/yzaslavs/Downloads/drawing.pdf PBM 2271x1610 2271x1610+0+0 16-bit Bilevel Gray 457KB 0.000u 0:00.000
Starting conversions.............
convert /home/yzaslavs/Downloads/drawing.pdf -resize 5000x5000\> out.png
out.png PNG 2271x1610 2271x1610+0+0 8-bit sRGB 383KB 0.000u 0:00.000
convert -resize 5000x5000\> -background white -depth 8 -density 160x160 /home/yzaslavs/Downloads/drawing.pdf out.png
out.png PNG 5000x3545 5000x3545+0+0 8-bit sRGB 1.943MB 0.000u 0:00.000
-------
convert -background white -depth 8 -density 160x160 -resize 5000x5000\> /home/yzaslavs/Downloads/drawing.pdf out.png
out.png PNG 5000x3545 5000x3545+0+0 8-bit sRGB 1.943MB 0.000u 0:00.000
-------
convert -background white /home/yzaslavs/Downloads/drawing.pdf -resize 5000x5000\> out.pn
out.png PNG 2271x1610 2271x1610+0+0 8-bit sRGB 383KB 0.000u 0:00.000
-------
convert -background white -depth 8 /home/yzaslavs/Downloads/drawing.pdf -resize 5000x5000\> out.png
out.png PNG 2271x1610 2271x1610+0+0 8-bit sRGB 383KB 0.000u 0:00.000
-------

Thank you in advance for any help

Upvotes: 0

Views: 170

Answers (1)

Mark Setchell
Mark Setchell

Reputation: 207808

This is how it works with ImageMagick v7:

# Basic, default density is 72dpi
convert -depth 8 a.pdf -resize 5000x5000\> info:
a.pdf PDF 595x842 595x842+0+0 8-bit sRGB 0.000u 0:00.000

# I specify density to match default and file comes out the same
convert -depth 8 -density 72 a.pdf -resize 5000x5000\> info:
a.pdf PDF 595x842 595x842+0+0 8-bit sRGB 0.000u 0:00.000

# I increase the density 10% and image gets 10% bigger - fair enough!
convert -depth 8 -density 80 a.pdf -resize 5000x5000\> info:
a.pdf PDF 661x935 661x935+0+0 8-bit sRGB 0.000u 0:00.000

# I double the density and the image doubles too - fair enough!
convert -depth 8 -density 144 a.pdf -resize 5000x5000\> info:
a.pdf PDF 1191x1684 1191x1684+0+0 8-bit sRGB 0.000u 0:00.000

# I quadruple the density and the image quadruples too
convert -depth 8 -density 288 a.pdf -resize 5000x5000\> info:
a.pdf PDF 2381x3368 2381x3368+0+0 8-bit sRGB 0.000u 0:00.000

# 8x density and image gets resized now too
convert -depth 8 -density 576 a.pdf -resize 5000x5000\> info:
a.pdf PDF 3535x5000 3535x5000+0+0 8-bit sRGB 2.700u 0:02.699

# Still bigger density and image still resized
convert -depth 8 -density 800 a.pdf -resize 5000x5000\> info:
a.pdf PDF 3535x5000 3535x5000+0+0 8-bit sRGB 3.890u 0:03.890

Upvotes: 1

Related Questions