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
Background floodfill with Imagick
Re: Background floodfill with Imagick
Hi,
if cyclops.png has transparent background you could just composite it on color ?
if cyclops.png has transparent background you could just composite it on color ?
Mikko Koppanen
My blog: http://valokuva.org
My blog: http://valokuva.org
Re: Background floodfill with Imagick
Sorry, but this doesn't look like an answer. 10xmkoppanen wrote:Hi,
if cyclops.png has transparent background you could just composite it on color ?
Re: Background floodfill with Imagick
Well, the only way I found to reproduce the above was this (yeah 18000 otherwise it won’t work 8-} [at least for me])
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
But I'm not very happy with this solution<?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;
?>
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
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
is this a new addition to Imagick?
Also, on my dev machine it doesn't work and I get
Code: Select all
Fatal error: Call to undefined method Imagick::paintFloodfillImage()
Re: Background floodfill with Imagick
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
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
Fortunately, on the production server the version is newer.
This code works quite well for me:
BTW: 12000 instead of 18000 worked better for me.
Thanks and good luck
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);
Thanks and good luck
Re: Background floodfill with Imagick
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)
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)