Page 1 of 1

Change color of image

Posted: 2010-12-23T08:05:01-07:00
by puneetsachdeva
Hi
I need to change colour of particular area in the image. I am a java developer. So, can use JMagick or other (sorry forgot its name) java api.

Image

In this image i want to change the sash and flower colour (currently in peach color) to any color at runtime, say fuschia, blue, green, etc.

I have tried on command line but it does not work for me. The command I used was

convert peach-flower.gif -fill white -draw -fuzz 13% 'color 162,60 replace' peachflowerwhite.gif

Got the following messages, the file peachflowerwhite.gif is created but with no changes

convert: Non-conforming drawing primitive definition `-' @ error/draw.c/DrawImage/3146.
convert: unable to open image `13%': No such file or directory @ error/blob.c/OpenBlob/2584.
convert: no decode delegate for this image format `13%' @ error/constitute.c/ReadImage/532.
convert: unable to open image `'color': No such file or directory @ error/blob.c/OpenBlob/2584.
convert: no decode delegate for this image format `'color' @ error/constitute.c/ReadImage/532.
convert: unable to open image `162,60': No such file or directory @ error/blob.c/OpenBlob/2584.
convert: no decode delegate for this image format `162,60' @ error/constitute.c/ReadImage/532.
convert: unable to open image `replace'': No such file or directory @ error/blob.c/OpenBlob/2584.
convert: no decode delegate for this image format `replace'' @ error/constitute.c/ReadImage/532.
convert: Non-conforming drawing primitive definition `-' @ error/draw.c/DrawImage/3146.

Any help is appreciated

Re: Change color of image

Posted: 2010-12-23T11:04:53-07:00
by fmw42
try moving -fuzz before the -draw

convert peach-flower.gif -fuzz 13% -fill white -draw 'color 162,60 replace' peachflowerwhite.gif


This works for me on IM 6.6.6.6 Q16, but the results are not very satisfying.

You will likely need to mask out the peach areas (by tracing) and then modify the image and composite them back so that where not peach you use the original and where it was peach you use the modified image. The composite operation allows you to use 3 image -- background overlay and mask.

see http://www.imagemagick.org/Usage/compose/#compose and http://www.imagemagick.org/Usage/layers/

Re: Change color of image

Posted: 2010-12-23T15:58:57-07:00
by anthony
In this case using a mask to mask out the background, and then modulating the hue of the colors may work better than attempting to directly modify those pixels.