how to place a resize image on a black layer, imagemagick - 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.

Related

how to imagemagick crop only width

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

How to use imagemagick to give background and dimensions to my screenshot?

I am new to Image Magick but am trying to get it to convert my image to a size and background pleasant for Twitter. The qualities I'm going for are as follows:
my overall canvas size 16:9, so about 1200x675
my actual screenshot centered and about 3/4 the width
background texture of my choosing
My latest attempt is with the following, but it doesn't seem to actually make any noticeable changes.
convert ds.png -adaptive-resize 1200 -size 1200x675 -texture ~/Pictures/DoctorWho/horizon.jpg -gravity Center ds.png
In Imagemagick 6, Unix syntax, if you just want to resize a small background image, then try
convert \( background.suffix -resize 1200x675 \) \( foreground.suffix -resize x506 \) -gravity center -compose over -composite result.suffix
If you want to crop a large image for the background, then try
convert \( background.suffix -gravity center -crop 1200x675+0+0 +repage \) \( foreground.suffix -resize x506 \) -gravity center -compose over -composite result.suffix
If you need to tile out a small image for the background, then
convert \( -size 1200x675 tile:background.suffix \) \( foreground.suffix -resize x506 \) -gravity center -compose over -composite result.suffix
For Windows remove the \ from the parentheses.
For Imagemagick 7, replace convert with magick.

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: center and resize multiple images an keep original filename

Good morning,
I'd like to center and resize multiple images in a folder with different aspect ratios and keep the filename. The following is nearly what I like to have (it works perfect for the particular picture), but there I have to name every specific pic.
convert -size 100x100 xc:black -gravity center originalpic.jpg -thumbnail 300x300 -composite newpic.jpg
I tried to work with * to keep the original file name and to process every file in the folder but without success. Does anybody know how to do that?
Thank you!
Use the mogrify command to work with multiple files.
mogrify -size 100x100 xc:black -gravity center -thumbnail 300x300 -composite *.jpg
Another way would be to iterate over the images in bash and use the same name as output to overwrite:
for f in *.jpg
do convert -size 100x100 xc:black -gravity center $f -thumbnail 300x300 -composite $f
done
I think I got it for me in general:
First size down to the height you want, e.g. to 364px:
mogrify -resize x364 *.jpg
And then, e.g. you want to get a dimension of 546x364px, this:
mogrify -extent 546x364 -gravity center *.jpg
But at image with original size of 512x768 background is getting filled with white color, so I tried
mogrify -extent 546x364 -gravity center -background black *.jpg
and
mogrify -extent 546x364 -gravity center -fill black *.jpg
but background is still white :-(

Use ImageMagick to place an image inside a larger canvas

Getting started with ImageMagic and trying to find a way to do this... If an image is less than 50 pixels tall or 50 pixels wide, I'd like to place it (un-scaled) in the horizontal/vertical center of a new 50x50 pixel canvas on top of a white background - and save that as the new image. Anyone know if this is possible with ImageMagick? Thanks!
I used -extent to do this:
convert input.jpg -gravity center -background white -extent 50x50 output.jpg
I wanted to do the same, except shrink the image to 70% inside. I used this:
convert input.png -resize 70%x70% -gravity center -background transparent -extent 72x72 output.png
Not exactly what was requested but hopefully it will help someone ;).
I have once used this code to place an image in the center of a new canvas with white background. hope this will help you
convert -background white -gravity center your_image.jpg -extent 50x50 new_image.jpg
See cutting and bordering for a huge number of examples. Here's one simple way you might do it:
convert input.png -bordercolor Black -border 5x5 output.png
Of course, you'll need to calculate the size of the border to add (if any) based on the dimensions of the input image. Are you using an ImageMagick API, or just the command line tools?
I tried this:
convert test.jpg -resize 100x100 -background black -gravity center -extent 100x100 output.png
You can use single composition to do this. So it would look something like this:
convert -size 50x50 xc:white null: ( my_image.png -coalesce ) -gravity Center -layers Composite -layers Optimize output.png
To modify the source image you need to use mogrify:
mogrify -gravity center -background white -extent 50x50 source.jpg
If an image is less than 50 pixels tall or 50 pixels wide
In my case, the images were much larger than the destination canvas, and weren't square. So I resize them proportionally to fit inside. Example:
convert in.png -resize 46x46 -background none -gravity center -extent 50x50 out.png
The 46x46 limit ensures a 2 pixel margin minimum. Note that the above does not distort the image, e.g. a rectangle does not become a square.
I used background none for a transparent background, but you can choose a solid color instead.

Resources