Set background color without changing image color

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
hknight
Posts: 32
Joined: 2007-08-02T10:16:15-07:00

Set background color without changing image color

Post by hknight »

I want my image to be 111x111 and I want the background to be red however I do not want the image to be too red. This code makes the part of the images that are not covered with the image red, which is good, however it also makes the image too red.

Code: Select all

convert -size 111x111 -crop 111x111+0+0 -background "red" rose: -unsharp 0x.5 \( +clone -shave 10x10 -fill gray50 -colorize 50% -mattecolor gray40 -frame 10x10+3+4 -blur 0x2 \) -compose HardLight -composite -gravity center -extent 111x111 -strip -quality 80 xyz.png
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Set background color without changing image color

Post by fmw42 »

Your command seems to have unnecessary and misplaced elements, in my opinion.

-size and -crop do nothing at the beginning of your command.

You have nothing to -strip with rose: image. Furthermore -quality 80 may not be a correct expression for -quality when using PNG output, it is certainly not a percent as with jpg. see http://www.imagemagick.org/script/comma ... hp#quality

Here is you command

convert -size 111x111 -crop 111x111+0+0 -background "red" rose: -unsharp 0x.5 -write 1tmp1.png \
\( +clone -shave 10x10 -fill gray50 -colorize 50% -mattecolor gray40 -frame 10x10+3+4 -blur 0x2 \) \
-compose HardLight -composite -gravity center -extent 111x111 -strip -quality 80 xyz.png


Here is how I would write it.

convert rose: -unsharp 0x.5 \
\( +clone -shave 10x10 -fill gray50 -colorize 50% -mattecolor gray40 -frame 10x10+3+4 -blur 0x2 \) \
-compose HardLight -composite -gravity center -background red -extent 111x111 xyz.png


There is an issue with either. The -extent is affected by the -compose hardlight. So you should reset the -compose to over afterwards. You get a totally different result.


convert rose: -unsharp 0x.5 \
\( +clone -shave 10x10 -fill gray50 -colorize 50% -mattecolor gray40 -frame 10x10+3+4 -blur 0x2 \) \
-compose HardLight -composite -compose over -gravity center -background red -extent 111x111 xyz.png


But if that is not what you want, then you need to clarify further. The use of hardlight may not be what you want here.
hknight
Posts: 32
Joined: 2007-08-02T10:16:15-07:00

Re: Set background color without changing image color

Post by hknight »

Perfect, thank you.
Post Reply