I found multiple ways to change the resolution of an image using convert:
-sample
-resample
-scale
-resize
-adaptive-resize
-thumbnail
What’s the difference of those?
If I need to make various size large picture thumbnail with fixed aspect ratio (cropping needed) — what’s my best choice?
resize
-resizedoes support an additional setting of-filter(which should occur on the commandline before using-resize!).-filterdetermines the exact algorithm to be used for the colors of added pixels in the case of magnification, or for the colors to be used for the remaining pixels when some of their neighbors are removed in case of minification.For a list of supported filters, simply run
convert -list filter.-filter point -resize 400x300creates exactly the same result as-sample 400x300does, but it runs still a bit slower.If not set alongside (before)
-resize, the conversion will silently default to-filter Lanczoswhich is slower, but which generates a much better quality (because it takes into account the colors of all surrounding pixels for any newly added ones) than-filter pointproduces (which uses the nearest neighbor rule to determine the color of a newly added pixels).sample
-sampledoes not support the additional setting of-filter; if set anyway, then-filteris simply ignored.When magnifying (because the input image size may be smaller than
400x300), pixels are replicated in blocks.When minifying (because the input image size may be larger than
400x300), pixels are sub-sampled with a very simple algorithm: some rows and columns are simply skipped over.The geometry argument to
-sampledoesn’t support any offset part (unlike-resize, which respects offset directives for the output).The output will never have more (different) colors than the input image had; it may have fewer colors though.
Therefore
-sampleis very fast (faster than-resize) — but output quality is (usually) worse: you can easily get extreme blocking and aliasing effects in the resulting output.One important feature of
-sampleis that the new image will not contain any new colors, though some colors from the original image may disappear.resample
This operation works only for such images which already have a desired resolution stored in their metadata (not all image formats do support the concept of an image resolution — JPEG, PNG and TIFF do).
If the source image is in a format where internal support for an image resolution is missing, then the (assumed) original resolution of the image must be specified via
-densityon the command line prior to specifying the-resampleresolution.scale
When minifying, it changes the image size simply by replacing pixel colors by averaging the respective input pixel colors together.
When magnifying, it simply replicates the respective input pixels for the required additional pixels.
adaptive-resize
-filter [something]).thumbnail
It is optimized for speed.
It also removes any embedded color profiles to reduce the filesize of the thumbnails.
The following answer shows a few (illustrated!) examples of the
-resizedirective. Each illustration shows a different result, depending on the ‘fine details’ of the exact resize method: