Resize every image to the same size - imagemagick

I need to resize any given image to 1200x700px without distorting it, no matter if the image is smaller or bigger. its okay when something gets cropped.
is it possible to do this in a simple way or do i need a lot of if/else to get there?
what's the best approach using imagemagick (command-line)?

convert image.suffix -resize "1200x700^" -gravity center -extent 1200x700 result.suffix

Related

Blur part of an image only

I would like to blur only a part of an image. The part to blur is always rectangular, so that I can easily use the following command:
magick source.jpg -region 1000x1000+0+500 -blur 0x20 result.jpg
This works, but is pretty slow for large images. Since I have to process thousands of files again and again, this will simply take too long.
Therefore, I decided to do the blurring by downscaling and upscaling the image back to the original size. However, since this will blur the full image, I have tried to accomplish the task using the following steps:
take the original image as background
create a copy of the original image
blur the copy using down-/upscaling
crop the desired region from the blurred copy
compose the original and the blurred&cropped copy
I am already pretty close (I hope), but when composing the two images, the cropped image will always be positioned in the top-left corner of the original image - instead of the original position from the source image. This is my current command:
magick source.jpg ( -clone 0 -resize 5% -resize 2000% -crop 1000x1000+0+1000 ) -composite result.jpg
I have read in the documentation that the original canvas size will be retained when using the -crop operation, and that this size and position will be used when using -composite. However, this doesn't seem to work in my case. Does anyone have an idea why?
I have tried to use -repage, -extent and other options to define the size and position of the cropped image, but to no avail so far.
I would try -flatten in your command as that is used for layers.
You can do it with a mask image (of any shape) in ImageMagick. Though I am not sure if that will be faster than your scaling method.
Input:
Mask:
(note: blurring occurs where mask is black)
magick lena.jpg -write-mask mask.png -blur 0x3 +write-mask lena_blurred.png
Result:

How to move an image on a canvas to a specific location using ImageMagick?

I am using ImageMagick to place an image on particular location on a white background canvas, can someone help me with it?
Here is what i tried so far, this would resize my image to correct resolution and put on a right size canvas.
Convert image.jpg -resize 1025x1537 -background white -extent 1920x1536
Now, I need to move it 40 pixles to the right , 20 to bottom
Reading the documentation for the geometry argument, it seems like one can use:
... -extent 1920x1536+40+20
If you want to define the offset from another origin, then you can use -gravity type.
https://imagemagick.org/script/command-line-processing.php#geometry
https://imagemagick.org/script/command-line-options.php#gravity

Imagemagick Crop image borders for lot of images with different sizes

I have a lot of images. Size of images are different.
I need to write the one imagemagick commandline operation to crop the borders of each image (for example, 10px of each edge).
Basic usage of -crop reuire to know the image geometry - it's not usefull.
Use -shave
convert montage.png -shave 10x10 montage.png

How to deal with padding in convert?

I am using convert from PDF to PNG.
$ convert -density 203.294113 -resize 6000x3300\> src.pdf[0] dst.png
But when the image is created, it has a white margin added around the origin pdf page and I don't know how to eliminate it (it doesn't matter whether "density" and "resize" are used). Thanks a lot for the help.
you can use -shave to remove border with specific size or -trim to auto-trim image

How to pixelate/blur an image using ImageMagick?

I want to pixelate and/or blur an image.
I've found the command for the blurring:
$convert image.jpg -blur 18,5 newimage.jpg
to work but I cannot blur the image any more.
And how do I pixelate the image? I couldn't find a sound example around the net.
Thx
To get a proper square pixellation, try:
convert -scale 10% -scale 1000% original.jpg pixelated.jpg
This worked nicely for me, gives a sort of cross between pixelating and blurring:
convert -resize 10% image.jpg newimage.jpg
convert -resize 1000% newimage.jpg newimage.jpg
You can be sure that the data cannot be retrieved, should that be important to you.
Changing the %ages will change the amount of pixelation/blur
I don't know anything about ImageMagick, but you can try resizing the image using bicubic to a much smaller dimension, then resizing the image back to a bigger one.
The trick works using .net's System.Drawing object.

Resources