Page 1 of 1
Background floodfill with Imagick
Posted: 2008-09-23T17:51:04-07:00
by colnector
My question is regarding creating a ‘fake’ transparent background with floodfill. I’ve managed to find an ImageMagick example but couldn’t figure out yet how to use Imagick to do the same.
Here:
http://www.imagemagick.org/Usage/channels/
”
convert cyclops.png -bordercolor white -border 1×1 -matte \
-fill none -fuzz 20% -draw ‘matte 0,0 floodfill’ \
-shave 1×1 cyclops_flood_3.png
”
Thanks
Re: Background floodfill with Imagick
Posted: 2008-10-15T05:49:35-07:00
by colnector
ping
Re: Background floodfill with Imagick
Posted: 2008-10-20T13:45:36-07:00
by mkoppanen
Hi,
if cyclops.png has transparent background you could just composite it on color ?
Re: Background floodfill with Imagick
Posted: 2008-10-20T18:16:46-07:00
by colnector
mkoppanen wrote:Hi,
if cyclops.png has transparent background you could just composite it on color ?
Sorry, but this doesn't look like an answer. 10x
Re: Background floodfill with Imagick
Posted: 2008-11-09T15:27:49-07:00
by QooooQ
Well, the only way I found to reproduce the above was this (yeah 18000 otherwise it won’t work 8-} [at least for me])
<?php
$cyclops= new Imagick("cyclops.png");
$cyclops->setFormat("png");
$cyclops->borderImage("white",1,1);
$cyclops->paintFloodfillImage ( "none" , 18000 , "#ffffff" , 1 , 1 );
$cyclops->shaveImage(1,1);
header("Content-Type: image/png");
echo $cyclops;
?>
But I'm not very happy with this solution
Maybe someone has a more propper translation of the ImageMagick Convert Command ?
?
?
My data:
Xampp 1.6.8 (Apache 2.2.9, PHP 5.2.6 + PHP 4.4.9 + PEAR)
php_imagick_st-Q16.dll
WinXp SP3
ImageMagick 6.4.5-4
Re: Background floodfill with Imagick
Posted: 2008-11-10T04:23:46-07:00
by colnector
This seems like a nice start but you've limited yourself to a known color (white) for the background. What's the easiest way to pick the color from an image's corner?
Also, on my dev machine it doesn't work and I get
Code: Select all
Fatal error: Call to undefined method Imagick::paintFloodfillImage()
is this a new addition to Imagick?
Re: Background floodfill with Imagick
Posted: 2008-11-11T07:17:35-07:00
by QooooQ
It seems that way
on
http://de.php.net/manual/de/class.imagick.php
its listed but not yet commented, so i was confused, if its integrated in imagick or not, but i tried and it worked.
So I guess you simply have to download a new version of imagick and then it should work for you, too
with
ImagickPixel Imagick::getImagePixelColor ( int $x , int $y )
you should be able to get the color of the corner, but I haven't tried this yet
Re: Background floodfill with Imagick
Posted: 2008-11-11T09:58:46-07:00
by colnector
Fortunately, on the production server the version is newer.
This code works quite well for me:
Code: Select all
$ipColor = $im->getImagePixelColor(1, 1);
$im->borderImage($ipColor, 1, 1);
$im->paintFloodfillImage("#e8f0fc", 12000, $ipColor, 1 , 1);
$im->shaveImage(1, 1);
BTW: 12000 instead of 18000 worked better for me.
Thanks and good luck
Re: Background floodfill with Imagick
Posted: 2008-11-11T17:36:49-07:00
by QooooQ
If you want to translate a % value of the ImageMagick convert command into the fuzz value of the paintFloodfillImage function...
0% equals 0
100% quals 65535
so to have a fuzz value of 20 % you need to enter 13107
with 12000 you got very close
In general (cite from Mikko):
Opacity values are usually 0.0 - 1.0 and color values are 0 - QuantumDepth (65535)