Page 1 of 1

MagickFloodfillPaintImage cannot remove the background

Posted: 2008-10-13T20:51:27-07:00
by colorpyen
Tried to use *floodfill* to remove background and make it transparent but failed to work.

I downloaded the latest MagickWand php extension 1.0.7 and compiled with ImageMagick 6.4.4.

However, I find it frustrating to get *Floodfill* kinds of functions working? The image after calling MagickFloodfillPaintImage() remains the same even with a large fuzz factor. I've also tried the PHP Imagick
extension(http://us2.php.net/imagick), still have the same problem.

Am I missing something here? I have been scratching my head for days to figure out this problem. Any help is highly
appreciated. Thanks a lot.

-peter


convert --version
Version: ImageMagick 6.4.4 2008-10-08 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2008 ImageMagick Studio LLC

// code sample using MagicWand PHP extension
<?php

$wand = NewMagickWand();
MagickReadImage($wand, 'test.png');
MagickFloodfillPaintImage($wand, NewPixelWand('transparent'), 50, NewPixelWand('white'), 10, 10);
echo MagickEchoImageBlob($wand);

?>

// code sampe using Imagick PHP extension
<?

$im = new Imagick('test.png');
$im->paintFloodfillImage(new ImagickPixel('transparent'), 50, new ImagickPixel('white'), 10, 10);
echo $im;

?>

Re: MagickFloodfillPaintImage cannot remove the background

Posted: 2008-10-14T09:00:41-07:00
by el_supremo
MagickFloodfillPaintImage($wand, NewPixelWand('transparent'), 50, NewPixelWand('white'), 10, 10);
There is an optional seventh argument to this function which specifies the channel(s) which are affected by the floodfill. I presume that the default is just the RGB channels, so the 'transparent' colour won't work. I don't know how to specify it in PHP but you need the equivalent of RGBA.
See http://www.magickwand.org/MagickFloodfi ... Image.html

Note to Anthony: it would be useful (to me, anyway :-) ) to have a reminder in the floodfill examples (http://www.imagemagick.org/Usage/color/#floodfill) that '-channel rgba' is needed when filling with any amount of transparency. And in the last sentence of that section, the reference to Transparency Masking is a dead link.

Pete