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.

Share:
7,138
Diego
Author by

Diego

Updated on September 17, 2022

Comments

  • Diego
    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
    Diego over 14 years
    Cool, 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
    John T over 14 years
    You're welcome! happy holidays :)
  • Diego
    Diego over 14 years
    Hm, 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
    Diego over 14 years
    Not even -size 720x480! (with the exclamation point!) does the trick.
  • John T
    John T over 14 years
    720x480 with 72 DPI? what is -density 72 -size 720x480 giving you? and with -resample 720x480?
  • Diego
    Diego over 14 years
    For 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
    John T over 14 years
    I mostly got money as gifts. Gonna go out and buy gizmo's tomorrow, this way I can choose what I want.