samb90
samb90

Reputation: 1073

ImageMagick Set Background Colour

I am attempting to use the following line of code to set the background colour of Image 1 to white.

(I.e. The first image 'Image1.png' needs to be cleared and become a blank white image. I then overlay Image 2 on top of this blank image)

Here is the line of code I am running in command line:

convert \( Image1.png -background white \) \( Image2.png -resize 250x105 \) -geometry +347+400 -composite -format jpg -quality 90 Image1.png

Alternatively, it would be better if I could generate a blank canvas for Image2.png to be placed upon. But I would like to get my first attempt using 2 images working first.

Upvotes: 0

Views: 230

Answers (1)

Mark Setchell
Mark Setchell

Reputation: 207345

Not too sure what you are trying to do, or how big image1 and image2 are supposed to be, but this should get you going if I just make up some stuff:

# Create image2 as red square coz I don't know better
convert -size 100x100 xc:red image2.png

# Create blue canvas and read in image2, resize it and splat it on top
convert -size 1000x1000 xc:blue \
       \( image2.png -resize 250x105\! \) \
       -geometry +347+400 -composite out.png

enter image description here

If you want to use image1 rather than create an empty canvas (presumably because image1 already has the correct dimensions or something), you can use it with my command like this whilst setting it to completely white in the process :

convert image1.png -evaluate set 65535 \
        \( image2.png -resize 250x105\! \) \
       -geometry +347+400 -composite out.png

Upvotes: 1

Related Questions