PHP 8.4.1 Released!

Imagick::paintTransparentImage

(PECL imagick 2, PECL imagick 3)

Imagick::paintTransparentImageGörüntüdeki belli bir rengi dolgu rengiyle değiştirir

Uyarı

Imagick 3.4.4 itibariyle bu işlevin kullanımı ÖNERİLMEMEKTEDİR. Bu işleve asla güvenilmemelidir.

Açıklama

public Imagick::paintTransparentImage(mixed $hedef, float $alfa, float $benzerlik): bool

Görüntüdeki belli bir rengi dolgu rengiyle değiştirir.

Bağımsız Değişkenler

hedef

Değiştirilecek renk.

alfa

Şeffaflık seviyesi: 1.0 tam mat ve 0.0 tam şeffaf.

benzerlik

Renkler arasındaki azami benzerlik. Örneğin bu değere 10 atarsanız, renk kırmızı ise ve kırmızının koyulukları 100 ve 102 ise bu iki renk aynı kabul edilir.

Dönen Değerler

Başarı durumunda true döner.

Hatalar/İstisnalar

Hata durumunda bir ImagickException istisnası oluşur.

Sürüm Bilgisi

Sürüm: Açıklama
PECL imagick 2.1.0 Artık renk olarak rengi ifade eden bir dizge belirtilebiliyor. Evvelce sadece bir ImagickPixel nesnesi belirtilebiliyordu.

add a note

User Contributed Notes 3 notes

up
1
Anonymous
15 years ago
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.
up
0
quickshiftin at gmail dot com
10 years ago
Have a look at this thread on Stackoverflow for the answer regarding how to determine the max intensity of an image.

http://stackoverflow.com/questions/26239130/determine-max-possible-intensity-of-image/26240656#26240656

In short here is the code to make the $fuzz parameter behave more like you would expect (it now represents a percentage between 0-100). The $fuzz value should now be a float between 0 and 1.

class SaneImagick extends Imagick
{
public function paintTransparentImage($target, $alpha, $fuzz)
{
$iQuantumDepth = pow(2, $this->getQuantumDepth()['quantumDepthLong']);
return parent::paintTransparentImage($target, $alpha, $fuzz * $iQuantumDepth);
}
}
up
0
alain at ocarina dot fr
13 years ago
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(320, 240, Imagick::FILTER_LANCZOS, 1, true);

// Apply fuzz
$im->paintTransparentImage($im->getImagePixelColor(0, 0), 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;';
}

?>
To Top