For example, if I have a large image that's 1600x1200, but I want to generate a thumbnail that is 250x200 (a different ratio of height and width) -- how can I scale this down to size and then center crop it? Is this possible in one line using convert?
Step 1: Right-click on the image and select Open. If Preview is not your default image viewer, select Open With followed by Preview instead. Step 2: Select Tools on the menu bar. Step 3: Select Adjust Size on the drop-down menu.
To crop an image using ImageMagick, you need to specify the X and Y coordinates of the top corner of the crop rectangle and the width and height of the crop rectangle. Use the mogrify command if you want the images to be replaced in-place or use the convert command otherwise to make a copy.
Image scaling is the process of resizing a digital image. Scaling down an image makes it smaller while scaling up an image makes it larger. Both raster graphics and vector graphics can be scaled, but they produce different results.
3. What is the difference between Resize and Skew commands? Answer: Resize allows you to make the image narrower, wider, shorter or longer.
If you want to scale down to 250x200 pixels (without keeping the aspect ratio), completely filling the space of 250x200 (stretching/distorting the image if necessary), use:
convert \
input.jpeg \
-scale 250x200\! \
output1.png
(Note the \!
characters after the scale geometry setting!)
Replace the .jpeg
and .png
suffixes with whatever format suffixes you have and want, ImageMagick will automatically handle it.
If you want to scale down to inside 250x200 pixels while keeping aspect ratio (the ratio of height to width) of the original image and cropping that dimension of the 250x200 pixels which isn't used up, use:
convert \
input.jpeg \
-scale 250x200 \
output2.png
By default width and height given in the -resize
argument are maximum values (unless you specify it as a percentage). This means: output images expand or contract to fit the specified dimensions, maintaining the aspect ratio of the image.
This command above "tries" to set the dimensions to 250x200:
When the height is shrunk to 200 pixels from the original's 1200 pixels (to 16.6666% of this original value), the width is now 266.66 pixels. So it doesn't fit yet....
When the width has shrunk to 250 pixels from the original 1600 pixels (to 15.625% of this original value) the height now is 187.5 pixels. So it fits now, and can leave over some space at the top and bottom.
So the final dimension will be either of 250x187 or more likely, 250x188 pixels (you can't have fractions of a pixel in the height, it requires an integer!).
If you want to scale down to inside 250x200 pixels, keeping aspect ratio of the original and creating an image that is the full-sized 250x200 pixels centering the real image in that space by adding some yellow background, use:
convert \
input.jpeg \
-scale 250x200 \
-gravity center \
-background yellow \
-extent 250x200 \
output3.png
Replace the background color with any other you like better, or with none
for transparent background (not supported for JPEG output!).
If you want to scale to 250x200 pixels keeping the aspect ratio, completely filling the space of 250x200 (but not cropping off any overflowing), use:
convert \
input.jpeg \
-scale '250x200^' \
output4.png
(Note the ^
character after the scale geometry setting. The ^
feature requires a minimum ImageMagick version of 6.3.8-2.)
When modifying width and height with the ^
addition to the -scale
or -resize
arguments, these settings are considered to be minimum values where only one of these too dimensions is really attained. This means: output images expand or contract until either width or height matches its specified dimension, maintaining the aspect ratio of the image.
This command above "tries" to set the dimensions to 250x200:
When the height is shrunk to 200 pixels from the original's 1200 pixels (to 16.6666% of this original value), the wanted scaling is achieved. Width is now 266.66 pixels. This is rounded to 267 pixels.
So the final dimension will be 267x200 pixels.
If you want to scale to 250x200 pixels keeping the aspect ratio, completely filling the space of 250x200 (cropping off strips from left and right edges), use:
convert \
input.jpeg \
-scale '250x200^' \
-gravity center \
-extent 250x250 \
output5.png
The final dimension of the image will be 250x200. Compared to the previous command (which gave a 250x267 result), some pixel columns from the left and right edges are removed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With