The command
imageconvert.exe in.jpg -resize 800x600 out.jpg
resizes the image so that it keeps original ratio, with maximum width of 800, and maximum height of 600 pixels. But if the image is smaller both in width and height (e.g. a 300x200 image), it will be enlarged to reach 800 or 600, and I don't want this.
How to keep the same kind of resizing (when width > 800 or height > 600), but such that an image that is smaller both in width and height (e.g. a 300x200 image), will be untouched?
I think you need the > flag on the resize. Let's create some images (one red 300x200, another blue 1000x500):
convert -size 300x200 xc:red small.png
convert -size 1000x500 xc:blue large.png
Now convert them both to 800x600 with no flags:
convert small.png -resize 800x600 a.png # 800x533
convert large.png -resize 800x600 b.png # 800x400
Now with flags:
convert small.png -resize 800x600\> a.png # 300x200
convert large.png -resize 800x600\> b.png # 800x400
You may need a caret (^) rather than a backslash on Windows.
The various flags are explained in the documentation here. Thanks to #user1133275 for the suggestion.
Related
I have a huge picture with a length of 388800 pixels and a height of 1920 pixels. I want to crop this picture horizontally into multiple small pictures of 1080*1920 pixels.
convert 1-all.png -crop 1080x1920 +repage -scene 1 doing1/1-%03d.png
What I got through the above command is only the first 20 pictures, not all 36 pictures
My original picture is as follows
enter link description here
Re-page your input image before you start cropping:
magick image.png +repage -crop 1080x1920 +repage -scene 1 DEBUG-%02d.png
I would like to zoom into an image test.png. That is, as a silly example, I would like to go from this
to this
The only way I was able to do it was with
convert -resize 110% test.png -gravity Center \
-crop 800x600+0+0 +repage 1.png
This is re-scaling the picture and then cropping it to its original size. The problem is that this only works because I already know that the original size of the image is 800x600.
How can I make this work without knowing the size of the image beforehand?
The way to do this, apparently, is with the -distort option:
convert -distort SRT '1.1 0' +repage test.png 2.png
where 1.1 is a 110% zoom and the 0 is a rotation angle.
I'm using graphicsmagick to resize an image to a thumbnail, but it's adding a white surrounding border padding.
The command I'm using is:
gm convert matrix.jpg -resize "80x80>" -gravity center -extent 80x80 thumbnail.jpeg
As you can see, there is some white padding around the image, but I don't want this. Ideally I'd like (the entire image not just a crop of it) to fill the desired 80x80 output size.
How can this be achieved in either imagemagick or graphicsmagick?
I used ImageMagick with this image. This solution requires to know the size of the input image.
Input
The image has 145 pixels horizontally and 200 pixels vertically.
Crop
Crop from the top of the image:
convert -crop 145x145+0+0 -resize 80x80 matrix.jpg thumbnail.jpeg
I used 145x145 in order to extract a square from the original image. +0+0 is the offset of the extracted square, hereby the top left.
Crop with the center of the image:
convert -crop 145x145+0+27 -resize 80x80 matrix.jpg thumbnail.jpeg
The vertical offset is set to 27 because we have to remove 55 (200 - 145) pixels on top or bottom, so we need to remove 27 (55 ÷ 2) pixels on the top and 28 pixels on the bottom.
Crop with the bottom of the image:
convert -crop 145x145+0+55 -resize 80x80 matrix.jpg thumbnail.jpeg
Resizing without crop
convert -resize 80x80\! matrix.jpg thumbnail.jpeg
The ! flag (escaped with \! as suggested in the documentation) after the resize parameters forces ImageMagick to ignore the aspect ratio.
If you want to keep the original aspect ratio, without image distortion, you can use the ImageMagick -trim option to get rid of the white padding:
convert "matrix.jpg" -resize "80x80" -gravity center -extent 80x80
-trim "thumbnail.jpg"
This will produce a 58x80 uncropped image with the same aspect ratio as the original. It is 58x80 because ImageMagick uses the larger dimension of the original to compute the scale factor (in this case 80/200) and scales the smaller dimension by that same factor to preserve aspect ratio.
If you want an uncropped image of exactly 80x80 pixels, this is a different aspect ratio than the original. The output image will have distortion, and #AL's resizing without crop option will work.
convert "matrix.jpg" -resize "80x80!" -gravity center -extent 80x80
"thumbnail.jpg"
Tested in Windows 7 with ImageMagick 6.8.9. #AL syntax is probably Linux.
When an image is rotated by convert -rotate command the image size is enlarged. Is there a way to rotate around the center and to keep the image size, cropping the edges?
convert image.jpg -distort SRT -45 rotate_cropped_image.png
See http://www.imagemagick.org/Usage/warping/#animations
Example:
See also help on -distort: http://www.imagemagick.org/script/command-line-options.php?#distort
This seems now to simply "just work" -- for counter-clockwise 90 degrees:
$ convert image.jpg -rotate -90 rotated_ccw.jpg
If you know the size of the image the following works:
convert -rotate 45 -gravity center -crop NxN input output
tested with square images.
there may be a way to specify NxN is the input image size.
I've found this answer on Imagemagick forum:
A simple solution without knowing what the original size of the image
was, is to use the Alpha Composite Operator 'Src' as a 'crop to this
image size' type of operation. See:
http://www.cit.gu.edu.au/~anthony/graphics/imagick6/compose/#src
For example (ImageMagick version 6 only):
convert image.jpg \( +clone -background black -rotate -45 \) \
-gravity center -compose Src -composite rotate_cropped_image.png
Im attempting to resize an image from 480x800 to 320x240. Below are the results. The original image has an oval shaped circle whereas the resized image has a more spherical shape. Is it possible to resize the original image so that the circle and rectangle are in their original proportions but smaller?
Can imagemagick or gimp (or other software) achieve this ?
Here's Imagemagick solution.
1) If you want large image to just fit 320x240 box and leave proportions, use:
convert test.png -size 320x240 resized.png
That will produce image sized 144x240.
http://www.imagemagick.org/Usage/resize/#resize
2) If you want large image to completely fill a specific image size, use:
convert test.png -resize 320x240\> \
-size 320x240 xc:blue +swap -gravity center -composite \
resized.jpg
That will produce image sized 320x240 with resized big image in center and blue fill on sides.
http://www.imagemagick.org/Usage/resize/#space_fill