ImageMagick's 'convert' won't set resolution?
7,138
-density
is not for resizing. From the ImageMagick page on density:
The -density option sets an attribute and does not alter the underlying raster image. It may be used to adjust the rendered size for desktop publishing purposes by adjusting the scale applied to the pixels. To resize the image so that it is the same size at a different resolution, use the -resample option.
-resample
is just a simple wrapper around the -resize
switch.
Author by
Diego
Updated on September 17, 2022Comments
-
Diego over 1 year
I'm trying to create an image using imagemagick's "convert".
I have this command:
convert -size 720x480 xc:white -units pixelsperinch -density 81x72 foo.jpg
However, the image ends up with a 72x72 resolution, rather than 81x72.
identify -verbose foo.jpg Image: foo.jpg Format: JPEG (Joint Photographic Experts Group JFIF format) Class: PseudoClass Geometry: 720x480+0+0 Resolution: 72x72 Print size: 10x6.66667
When I run
convert
with-resample 81x72
rather than-density
, I get the correct resolution. Why is this? -
Diego over 14 yearsCool, I didn't quite realize that it was just "modifying some arbitrary header" rather than actually setting the size; thank you for pointing out that part of the doc!
-
John T over 14 yearsYou're welcome! happy holidays :)
-
Diego over 14 yearsHm, one more question: when I change to "resample", it changes the dimensions of my image (to 810x480). Do you know what I need to do to create an image which forces both my desired DPI and the desired dimensions?
-
Diego over 14 yearsNot even
-size 720x480!
(with the exclamation point!) does the trick. -
John T over 14 years720x480 with 72 DPI? what is -density 72 -size 720x480 giving you? and with -resample 720x480?
-
Diego over 14 yearsFor reasons that are magical to me,
convert -density 81x72 -size 720x480
was the incantation I needed to make it work. I tried "-density" again after your comment. Thanks again! (shouldn't you be playing with some new gizmo gift rather than tinkering on superuser? :-) -
John T over 14 yearsI mostly got money as gifts. Gonna go out and buy gizmo's tomorrow, this way I can choose what I want.