ImageMagick: reduce image size
Asked Answered
L

2

9

I am using ImageMagick to reduce the image resolution, height and width.

I have noticed a few things. When I am changing resolution at "Image Size" through Photoshop (version 7) from 300dpi to 150dpi image height and width automatically change.

With ImageMagick however I am not getting such variations. For example, if image contains 878 width and 179 height at 300dpi, when changing it to 150 dpi, automatically the image width changing to 439 and height 89 respectively.

Can any one support me how to obtain such changes through ImageMagick.

Lewendal answered 2/1, 2015 at 10:35 Comment(0)
B
10

The dpi setting is not really relevant in most imaging applications/areas, until the point at which you want to print an image.

Do you really need to set it? I mean, if you want to half the size of an image, just use ImageMagick and do:

convert input.jpg -resize 50x50% output.jpg

and ignore the dpi.

Bankroll answered 3/1, 2015 at 21:52 Comment(0)
A
10

To resize the image keeping the rendered size the same, you can use the -resample option, like so:

$ convert original.jpg -resample 150x150 new.jpg

Using your example, if the original is an 878x179 image at 300DPI, the result is an 439x90 image at 150DPI:

$ file original.jpg
original.jpg: JPEG image data, JFIF standard 1.01, aspect ratio, density 300x300,
              segment length 16, baseline, precision 8, 878x179, frames 3
$ file new.jpg
new.jpg: JPEG image data, JFIF standard 1.01, aspect ratio, density 150x150,
         segment length 16, baseline, precision 8, 439x90, frames 3

You can alternatively use the -density option along with the -resize option to achieve the same effect:

$ convert original.jpg -density 150x150 -resize 50%x50% new.jpg

In summary:

  • -density just sets the DPI metadata without changing the underlying image;
  • -resize changes the image size without changing the DPI;
  • -resample changes the DPI and resizes the image accordingly.

Uses

The DPI metadata is relevant when you need to print an image or convert it to a PDF.

Now you can convert both images to PDF and get files with essentially the same page size:

$ convert original.jpg original.pdf
$ convert new.jpg new.pdf
$ pdfinfo original.pdf  | grep -a "Page size:"
Page size:      210.72 x 42.96 pts
$ pdfinfo new.pdf | grep -a "Page size:"
Page size:      210.72 x 43.2 pts
Anglicist answered 28/10, 2017 at 11:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.