changing an image background 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
nightowl

changing an image background color

Post by nightowl »

Hello everyone! 8)

I try to learn imagemagick on my kubuntu dapper drake OS.

I tried to change the background color of an image i created first with:
convert -size 1400x1100 xc:black blackos.jpg

then:
convert blackos.jpg -background white whitos.jpg

The trouble is that the color remains the same! And strangely if i have a look at the image with identify it says the background is white!

nobody@nowhere:~$identify -verbose blackos.jpg
blackos.jpg JPEG 1400x1100 PseudoClass 256c 6kb
Image: blackos.jpg
Format: JPEG (Joint Photographic Experts Group JFIF format)
Geometry: 1400x1100
Class: PseudoClass
Type: Grayscale
Endianess: Undefined
Colorspace: Gray
Channel depth:
Gray: 1-bits
Channel statistics:
Gray:
Min: 0 (0)
Max: 0 (0)
Mean: 0 (0)
Standard deviation: 0 (0)
Colors: 256
Histogram:
1540000: ( 0, 0, 0) black
Rendering-intent: Undefined
Resolution: 72x72
Units: PixelsPerInch
Filesize: 6kb
Interlace: None
Background Color: white
Border Color: #DFDFDF
Matte Color: grey74
Dispose: Undefined
Iterations: 0
Compression: JPEG
Quality: 100
Orientation: Undefined
JPEG-Colorspace: 1
JPEG-Sampling-factors: 1x1
Signature: a11c1a7febfddd74d71a48977501c3a06f0db340b44795fd74fc825ab2f44d4b
Tainted: False
Version: ImageMagick 6.2.4 10/02/07 Q16 http://www.imagemagick.org


What can be wrong with that in fact?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: changing an image background color

Post by Bonzo »

I can only assume the background is white but it is covered completly by blackos.jpg

What you are doing will not work, if you want to do that you will need to select the black and change it to white.

Code: Select all

convert blackos.jpg -fill white -opaque black whiteos.jpg
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: changing an image background color

Post by anthony »

The -background SETTING is a image meta-data setting that usally does not effect the image itself. You need to modify the image, not modify the setting.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
nightowl

Re: changing an image background color

Post by nightowl »

Weel, thanks.
In fact i found out that to change the background color, you can use the "draw" command. That works very well for that purpose.
Post Reply