Replacing a one color with another

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
jumpman25

Replacing a one color with another

Post by jumpman25 »

hi there,
i am trying to figure out how to change the color of an image from one to another. The code below works but i need to specify one pixel as a target. I want this to be used for multiple images, so if i have to specify a target pixel every time it won;t work.

$magick_wand=NewMagickWand();
$drawing_wand=NewDrawingWand();
$pixel_wand=NewPixelWand();
$pixel_wand_bk=NewPixelWand();

MagickReadImage($magick_wand,'apple.png');

PixelSetColor($pixel_wand_bk,"black");
DrawSetFillColor($drawing_wand,$pixel_wand_bk);

DrawColor($drawing_wand, 0, 0, MW_ReplaceMethod);

PixelSetColor($pixel_wand,"red");
DrawSetFillColor($drawing_wand,$pixel_wand);

DrawColor($drawing_wand, 200, 200, MW_ReplaceMethod); (This kinda works but i need to specify one pixel as a target.)

MagickDrawImage($magick_wand, $drawing_wand);
MagickWriteImage($magick_wand, "apple2.png" );


This code works from the command line for all the images i have. How can i use this from Magickwand?

convert apple.png ( +clone -fill red -colorize 100% ) -composite primary_colors.png
Post Reply