Ways to Resize Images with GraphicsMagick
It's confusing how many ways there are to scale images with GraphicsMagick. I've listed and compared the various options to find which one is best in practice.
1 Changing Sizes
These options are to be used for changing the dimensions of images. I started from the following original image which I intend to scale down to 50% and compare the resulting qualities.
1.1 -geometry
-geometry <width>x<height>{+-}<x>{+-}<y>{%}{@}{!}{^}{<}{>}
The -geometry
option comes with an amazing variety of options to change an object's size, with different expressions, keeping the ratio or not, setting upper and lower limits. They help you express in a unique and same way how to change the geometry of large amounts of images, no matter their dimensions and orientations.
1.2 -resize
-resize <width>x<height>{%}{@}{!}{<}{>}
The manpage says about the -resize
option that it's an alias for the -geometry
option and that it behaves the same way. They make a note about preceding it with the -filter
option to affect the resize operation. There are many filters to choose from and the default ones (Mitchell or Lanczos) are among the ones offering the best quality. It's worth noting that the -geometry
option is also affected by a preceding -filter
option. Finally, while it appears that -geometry
supports a wider range of expressions to describe a change of size, it's worth noting that when used with gm convert
, offset are ignored. As a result, -resize
and -geometry
are really identical when it comes to gm convert
.
1.3 -sample
-sample <width>x<height>{%}{@}{!}{^}{<}{>}
The -sample
option uses pixel sampling which results in the worst quality compared to other options. It ignores preceding -filter
options and offsets. It's probably only interesting where speed matters.
1.4 -scale
-scale <width>x<height>{%}{@}{!}{^}{<}{>}
The -scale
option is faster than -geometry
(and so -resize
) and the quality is perceptibly a bit worse. It ignores preceding -filter
options and offsets. It's worth noting that if both the -size
and -resize
options are available, there is no such thing as a -rescale
option.
2 Unrelated Options
Some options offered by gm convert
aren't actually involved in changing the dimensions of images. But this isn't obvious from their names. In particular, I identified the following ones.
2.1 -size
-size <width>x<height>{+offset}
The -size
option is not for resizing images at all, but for specifying the dimensions of an image whose dimensions are unknown. As a result, it is completely unrelated to the other options. It only allows for a much simpler expression of the geometry, even if offsets are taken into account.
2.2 -resample
-resample <horizontal>x<vertical>
It is more on the resolution (i.e. pixel per real-life unit) that the -resample
option operates. As a result, this option is somewhat unrelated to the other ones discussed here.