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

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

Related

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

Enlarge image canvas to compensate for blur

I have an image that I am processing with imagemagick to add a blur:
convert input.png -blur 0x16 output.png
However the blur is cropped as it goes outside the frame of the image. How can I compensate for this and enlarge the canvas to allow the blue to be fully shown?
Example image here
The image you have linked is a JPEG, not a PNG, like your command suggests, so I have no idea if it has transparency, or whether it is supposed to have lots of spare canvas around the image of the TV. As such, I am guessing what you want.
You can extend the canvas out from the centre by specifying -gravity center and using -extent so that you have space for the blur like this:
convert image.jpg -gravity center -extent 120%x120% -blur 0x16 output.jpg
However, that introduces more canvas than you need, so you may want to trim it afterwards, like this:
convert image.jpg -gravity center -extent 120%x120% -blur 0x16 -trim output.png
As an alternative, you could add some white border (I chose 500 px all round) like this:
convert image.jpg -bordercolor white -border 500x500 -blur 0x16 output.png
and remove however much you wanted to afterwards with -shave like this:
convert image.jpg -bordercolor white -border 500x500 -blur 0x16 -shave 400x400 output.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 :-(

change the background of an image in image magick

I am using this command for imagemagick to extend the size of an image and background to white
convert input.png -extent 495X320 -gravity center -background white output.jpg
The size is doing extent but the background is black every time. I tried many methods but the same black is coming every time.So can some one help me how to solve this. Any help and suggestions will be highly appreciable.
The order is important here, use -background before -extent:
convert input.png -background white -extent 495X320 -gravity center output.jpg
Leaving this for people that have tried the other answer but it still does not work.
In my case I needed
convert image.png -resize 80% -quality 80% -background white image-edited.jpg
Add the -flatten option at the end and it should work. So like:
convert image.jpg -resize 80% -quality 80% -background white -flatten image-edited.jpg

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