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
Related
I am in a situation where I have a set of images with variable width and height and I need to ensure that those images comply with an aspect ratio of 2:1.
The only assumption I can make is that those images have an aspect ratio greater than 2 so I need to expand the canvas.
With ImageMagick I can do this:
magick input.jpg -background black -gravity north -extent 2:1 output.jpg
But this crops instead of adding canvas as desired. Is there an option to avoid cropping, i.e. force image padding? Remember I do not know the image resolution beforehand.
Of course with a more complex script I can extract the image dimensions and compute the desired resolution but I am trying to keep things simple if possible.
P.S.: The images comes from a laser scanner and are going to be used in a 360 panorama viewer hence the need to meet an aspect ration without cropping.
With ImageMagick v7 you can do some inline calculations that will adjust the results of the -extent operation to pad any size input to a 2:1 ratio. See this command as an example...
magick input.png -gravity center -extent "%[fx:max(w,h*2)]x%[fx:max(w/2,h)]" result.png
That will pad any extra space with black. Add -background <somecolor> before the extent operation to change the padding color.
I have portrait and landscape JPEG images.
I want to make square thumbnails with white background from all of them. I need to keep the aspect ratio of all images and reduce the larger border to 200px.
I want to use ImageMagick (CLI) but I don't know how to do that. Any idea ?
Here is the individual images :
I think you need this:
convert -background white -gravity center \
input.jpg -resize 200x200 -extent 200x200 result.jpg
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.
I would like to generate thumbnails for my website. Now I am using the following to process folder (based on this answer):
mogrify -interlace Plane -thumbnail 280x210^
-gravity center -extent 280x210 -quality 85% *.jpg
This will create thumbnails with given size (resize and crop).
I also have single image version of this command:
convert test.jpg -interlace Plane -thumbnail 280x210^
-gravity center -extent 280x210 -quality 85% testout.jpg
I'm also using facedetect to get positions of faces from the original image (before creating thumbnails). For photos with faces I have calculated average X, Y position of faces center.
Now, I would like to use this position in the command above to crop pictures smarter. Currently image is cropped from both sides (-gravity center), but I would like to use my coordinates so faces are displayed when image is cropped.
Is there a way how I can feed this into imagemagick?
You could use -shave to remove part of the image, so that the face moves to the center, then apply your original command.
OK. I have a horizontal image, let's say 2000 x 300. I want to overwrite that image and create a new one that is 2000 x 2000 with the old image center in the middle and vertically, with white space around it. I also want to do this in batch with many different images of different sizes. Thanks in advance.
Use -resize to resize the image to 2000x2000, -background to set the background to white, -gravity to center the original image on the canvas, and -extent to resize the canvas itself (to cause the image to sit in the centre if it wasn't square originally).
convert [imagename] -resize 2000x2000 -background white \
-gravity center -extent 2000x2000 [imagename]