Imagick::paintTransparentImage

(No version information available, might be only in CVS)

Imagick::paintTransparentImage — Changes any pixel that matches color with the color defined by fill

Описание

bool Imagick::paintTransparentImage ( mixed $target , float $alpha , float $fuzz )
Внимание

К настоящему времени эта функция еще не была документирована; для ознакомления доступен только список аргументов.

Changes any pixel that matches color with the color defined by fill.

Список параметров

target

Change this target color to specified opacity value within the image.

alpha

The level of transparency: 1.0 is fully opaque and 0.0 is fully transparent.

fuzz

The fuzz member of image defines how much tolerance is acceptable to consider two colors as the same.

Возвращаемые значения

Returns TRUE on success.

Errors/Exceptions

Throws ImagickException on error.

Список изменений

Версия Описание
2.1.0 Now allows a string representing the color as the first parameter. Previous versions allow only an ImagickPixel object.

Коментарии

Fuzz attribute doesn't work here.

#!/usr/bin/php
<?php

if(!isset($argv[1])) die("input file\n");

$im = new Imagick$argv[1] );
$im->paintTransparentImage('rgb(246,241,230)'0.010);

file_put_contents('transparent_'.$argv[1], $im);
?>

Will "remove" only colors that match exactly rgb(246,241,230)
2009-02-13 16:53:03
http://php5.kiev.ua/manual/ru/function.imagick-painttransparentimage.html
Автор:
Actually it does seem to work just not the way expected perhaps.

Looking at the fuzz option on ImageMagick's site (http://www.imagemagick.org/script/command-line-options.php#fuzz), "The distance can be in absolute intensity units or, by appending % as a percentage of the maximum possible intensity (255, 65535, or 4294967295)."

As it requires a float, the percentage value won't work so it actually one of the max intensity values.  In my case, the images I was working with seemed to have max intensity values of 65535.  So a fuzz of 6500, for roughly 10%, seemed to do the trick.

The part that might be problematic though is how do you determine the max intensity of a color/image?  Using a static 6500 would be fine until I would have to convert an image with a max intensity other than 65535.  If it's 255 it would wipe the entire image.  Or fall far short on the fuzz with the larger value.
2009-03-06 18:11:59
http://php5.kiev.ua/manual/ru/function.imagick-painttransparentimage.html
The fuzz is just working well in a range of 0 to 65535.

I suggest you to try to move fuzz on a color spectrum image.

1/ Get a color spectrum ( Google Image has a lot )

2/ Try this code :

<?php

   
function fuzzTest($source$target$fuzz) {

       
// Loads image
       
$im = new Imagick($source);

       
// Resizes images to make them easily comparable
       
$im->resizeImage(320240Imagick::FILTER_LANCZOS1true);
       
       
// Apply fuzz
       
$im->paintTransparentImage($im->getImagePixelColor(00), 0$fuzz);
       
         
// Writes image
       
$im->setImageFormat('png');
       
$im->writeImage($target);
       
$im->destroy();
         
        return 
true;
     }

     for (
$i 0; ($i <= 10); $i++) {
         
fuzzTest('spectrum.png'"test_{$i}.png", (6553.5 $i));
         echo 
'<img src="test_' $i '.png" />&nbsp;';
     }
 
 
?>
2011-10-18 00:14:48
http://php5.kiev.ua/manual/ru/function.imagick-painttransparentimage.html

    Поддержать сайт на родительском проекте КГБ