Page 1 of 1

Trying to replace certain colors

Posted: 2007-06-11T13:32:54-07:00
by leeh
Hi i was trying to swap out colors from a template image with other colors, i decided to use the MagickPaintFloodfillImage function to do this. I am not sure if this was a good choice; I am running that function through PHP and was wondering if my code below is correct.

Code: Select all

<?php

$r = NewMagickWand();

MagickReadImage($r, 'redblack.JPG');

$color = NewPixelWand();
PixelSetColor($color, "blue");
$border = NewPixelWand();
PixelSetColor($border, "black");

echo "working checkpoint<br>";

if ( MagickPaintFloodfillImage( $r, $color, 0, $border, 50, 50) != 0 )
{
	echo "success";
	// MagickEchoImageBlob( $r );
}
else
{ 
	 echo MagickGetExceptionString($r);
}
?>
I can get to the "working checkpoint" string but nothing happens afterwards, so this makes me wonder if i'm using the function correctly. Example codes online work with my image but this is my first personal attempt with imagemagick that didn't turn out right.

Also i don't seem to get any error messages, this is really limiting my debugging.

Re: Trying to replace certain colors

Posted: 2007-06-11T14:13:41-07:00
by Bonzo
If using php I would try this ( from an old post http://redux.imagemagick.org/discourse- ... ange+color )

Code: Select all

<?php
exec("/usr/local/bin/convert original.jpg -fill rgb\(255,0,0\) -opaque rgb\(170,170,170\) output.jpg");  
?>
-fill is the new colour and -opaque is the colour to change. You can use colour names rgb, hex etc. Adding a -fuzz will give you a range of shades around the colour you want to change.

Re: Trying to replace certain colors

Posted: 2007-06-11T15:27:57-07:00
by leeh
Thanks, that code worked... but but made me realize the folder had to have a chmod of 777... which isn't what i was looking forwards to.

Thanks though!

also this works:

Code: Select all

exec("convert black.JPG -fuzz 10 -fill '#345678' -opaque black new_black.jpg");
for those like me who like to deal with hex

Re: Trying to replace certain colors

Posted: 2007-06-11T18:40:01-07:00
by anthony
You don't have to write out the image. You can output it to stand out.

<?PHP
header( 'Content-Type: image/jpeg' );
exec("convert original.jpg -fill rgb\(255,0,0\) -opaque rgb\(170,170,170\) JPG:-");
?>
see IM Examples Feedback page
http://www.imagemagick.org/Usage/feedback.html#php