Replacing Hexidecimal Colours in Image

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
deklin
Posts: 5
Joined: 2016-03-07T10:09:35-07:00
Authentication code: 1151

Replacing Hexidecimal Colours in Image

Post by deklin »

I am trying to replace yellow with blue.

This does NOT work:

Code: Select all

convert image.gif -fill #FFE087 -opaque #0000CC imageblue.gif
Image
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Replacing Hexidecimal Colours in Image

Post by snibgo »

You have "-fill" and "-opaque" the wrong way round.
snibgo's IM pages: im.snibgo.com
deklin
Posts: 5
Joined: 2016-03-07T10:09:35-07:00
Authentication code: 1151

Re: Replacing Hexidecimal Colours in Image

Post by deklin »

This doesn't work either:

Code: Select all

convert image.gif -opaque #FFE087 -fill #0000CC imageblue.gif
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Replacing Hexidecimal Colours in Image

Post by snibgo »

"-opaque" is an operation. It turns pixels from whatever colour you say to the fill colour. By default, the fill colour is white. If you want to make the fill colour blue, you must set it before the "-opaque" operation.
snibgo's IM pages: im.snibgo.com
deklin
Posts: 5
Joined: 2016-03-07T10:09:35-07:00
Authentication code: 1151

Re: Replacing Hexidecimal Colours in Image

Post by deklin »

I am working with an animated GIF.

Code: Select all

convert image.gif -fill #0000CC -opaque #FFE087 imageblue.gif
That works on one frame only. The color is changed on one frame only.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Replacing Hexidecimal Colours in Image

Post by snibgo »

It should work on all your frames. Any frames that contain #FFE087 will have that colour changed. But only one frame contains that exact colour. Other frames have similar but not exactly the same colours. You can see this with:

Code: Select all

convert image.gif -unique-colors +append txt:
So you need a "-fuzz".
snibgo's IM pages: im.snibgo.com
Post Reply