how to imagemagick crop only width - imagemagick

im trying to crop an image of size 1920x125058 into 900x125058 from the center
so I used magick convert in.png -crop 900x+510+0 out.png but this outputs a file of size 900x28800. shouldn't the height be untouched if it is not mentioned?

In Imagemagick 7, use magick, not magick convert. For center cropping, use -gravity center
magick in.png -gravity center -crop 900x125058+0+0 +repage out.png

Related

ImageMagick: convert image from landscape to portrait orientation

I'm trying to convert an image from landscape to portrait orientation with the command below:
convert sample_img.jpg -resize 1670x760 -gravity Center -background white -interlace plane -extent 1670x2288 vertical_img.jpg
Unfortunately both -gravity Center and -gravity South are not suitable for the result that I would like to achieve, is it possible to specify the height in pixel?
I found the splice option, using it I was able to obtain an image as desired with:
convert sample_img.jpg -resize 1670x760 -extent 1670x1188 -gravity north -splice 0x1100 vertical_img.jpg

Imagemagick create image and place image inside with max size

I have trimmed .pngs and need them placed on a canvas (3000x3000 px) BUT with a max size.
convert -size 3000x30000 xc:transparent test.png -gravity south -composite -size 2200x2200 result.png
The code I have now works, but the sizing of the image is off. My canvas is 3000x3000px as intended, but the image placed on the canvas doesn't have the correct size. It should have a max width/height of 2200px and if possible be scaled up, if they are to small in height.
This ImageMagick command will resize the input image to 2200 pixels on the longer side while maintaining its aspect, then create a 3000x3000 transparent canvas, then swap the input image and the canvas, and finish by compositing the resized input image onto the transparent canvas...
convert input.png -resize 2200x2200 \
-size 3000x3000 xc:none +swap -gravity south -composite result.png
For Windows change that continued line backslash "\" to a caret "^". For ImageMagick v7 use "magick" instead of "convert".
Unix syntax:
convert -size 3000x30000 xc:transparent \( test.png -resize 2200x2200 \) -gravity south -composite result.png
Windows syntax:
convert -size 3000x30000 xc:transparent ( test.png -resize 2200x2200 ) -gravity south -composite result.png
Why not use -extent?
convert input.jpg -resize 2200x2200 -background none -gravity south -extent 3000x3000 result.png

ImageMagick script takes JPG and places on canvas but changes colour of JPG

I would like to take this logo and place it on a black background.
I am using the below script
convert -size 4000x4000 canvas:#000000 -background \#000000 background.jpg
composite rev.jpg -gravity center background.jpg output.jpg
open output.jpg
Which generates. As you can see the colours have changed and I cannot work out why?
Just set the colorspace.
composite 03wp2.jpg -colorspace srgb -gravity center background.jpg output.jpg
Possibly a colour profile or are you using CMYK for the rev.jpg?
Try this which will shorten your code:
convert rev.jpg -background black -gravity center -extent 4000x4000 output.jpg

Batch crop image having variable height

I want to batch crop images having variable height. I have fixed width, x and y coordinates value but not the height value. I tried the code mentioned below but it didn't work. Only top, left and right side needs to be cropped.
mogrify -crop 320xauto+864+323 +repage image.png
Use -chop instead of -crop:
mogrify -chop 864x0 +repage image.png
mogrify -chop 0x323 +repage image.png
mogrify -gravity East -chop 333x0 +repage image.png

how to place a resize image on a black layer, imagemagick

I would like to take a picture, resize it to 50% and put it on a black layer...
My issue is that resizing the image, resize the whole image (with the black layer too)and put it at the center of the new layer...
here's my code:
'convert -size 1920x1080 xc:Black -gravity center image.png -resize 20% -composite -flatten result.png'
how could I do to just resize the image.png and not the whole layer ?
thanks in advance
g.
I think you probably want this:
convert image.png -resize 50% -gravity center -background black -extent 1920x1080 result.png
Or this, which is another way of doing the same thing:
convert -size 1920x1080 xc:black \( image.png -resize 50% \) -gravity center -composite result.png
Or, a more succinct version:
convert xc:black[1920x1080\!] \( image.png -resize 50% \) -gravity center -composite result.png
The first one resizes your image and then extends it with black from the centre outwards to your desired size.
The second creates the correctly sized canvas, then loads your image and resizes it "on-the-side" in parentheses and composites the result onto the canvas.

Resources