Page 1 of 1

Replacing a one color with another

Posted: 2007-09-03T10:39:50-07:00
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