You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It looks like ImagickPixel::isSimilar is not working as described.
$red250 = new ImagickPixel('rgb(250, 0, 0)');
$pureRed = new ImagickPixel('rgb(255, 0, 0)');
$isSimilar = $pureRed->isSimilar($red250, 1);
var_dump($red250->getcolor(true));
var_dump($pureRed->getcolor(true));
echo "pure red and red250 ";
if ($isSimilar) {
echo "are similar";
}
else{
echo "are not similar.";
}
outputs
array (size=4)
'r' => float 0.98039215686275
'g' => float 0
'b' => float 0
'a' => float 1
array (size=4)
'r' => float 1
'g' => float 0
'b' => float 0
'a' => float 1
pure red and red250 are not similar.
Changing the fuzz factor to 1000 makes the colours be similar, but that is a fuzz factor that is much larger than ever should be used - according to the manual.
It looks like this may be failing in the tests, FAIL Test filling thumbnail with color [tests/007_thumbnail_fill.phpt]
Additionally, the function accepts things that are not of type ImagickPixel as the first parameter. I'm not sure if thats bug or a feature.
I think the 007 test fails on some imagemagick versions because setImageBackgroundColor behaves differently. I added a skip for known faulty versions.
Other than that the parameters are passed directly to the MagickWand API. Which manual are you referring to with the fuzz parameter?
As for the function accepting something else than imagickpixel, this is true for all methods that accept imagickpixel (they also accept string of valid color). Such as setBackgroundColor ('pink') and setBackgroundColor (new ImagickPixel ('pink'));
Checks the distance between the color described by this ImagickPixel object and that of the provided object, by plotting their RGB values on the color cube. If the distance between the two points is less than the fuzz value given, the colors are similar.
The maximum distance within which to consider these colors as similar. The theoretical maximum for this value is the square root of three (1.732).
The distance between the two colours should be (5 / 256) which should be found to be less than one.
You were right that the fuzz value needs to be scaled by the QuantumRange.
But I'm also getting more convinced the function IsMagickColorSimilar is also just broken. In it the fuzz factor is being multiplied by 3 (because of 'reasons'), but the distance comparison isn't being multiple by 3.
Activity
mkoppanen commentedon Oct 16, 2013
I think the 007 test fails on some imagemagick versions because setImageBackgroundColor behaves differently. I added a skip for known faulty versions.
Other than that the parameters are passed directly to the MagickWand API. Which manual are you referring to with the fuzz parameter?
As for the function accepting something else than imagickpixel, this is true for all methods that accept imagickpixel (they also accept string of valid color). Such as setBackgroundColor ('pink') and setBackgroundColor (new ImagickPixel ('pink'));
Danack commentedon Oct 16, 2013
Sorry, I was referring to the PHP manual http://php.net/manual/en/imagickpixel.issimilar.php
The distance between the two colours should be (5 / 256) which should be found to be less than one.
mkoppanen commentedon Oct 17, 2013
Is the parameter fuzz given in the quantum range?
Danack commentedon Oct 17, 2013
I think the underlying function may just be broken.
It's giving wildly different results for when an Alpha is set, and when it isn't
Changing between the red with and without alpha gives:
i.e. the behaviour of the function just completely changes.
I'll setup some tests to see if I can figure it out.
mkoppanen commentedon Oct 17, 2013
http://www.imagemagick.org/Usage/bugs/fuzz_distance/ ?
Danack commentedon Oct 17, 2013
You were right that the fuzz value needs to be scaled by the QuantumRange.
But I'm also getting more convinced the function
IsMagickColorSimilaris also just broken. In it the fuzz factor is being multiplied by 3 (because of 'reasons'), but the distance comparison isn't being multiple by 3.e.g. the calculation is being done as
I'm testing rgb(245, 0, 0) against rgb(255, 0, 0) with a distance of 6
With some debugging added the final compare that it's doing is:
So it's just getting the wrong value, because the fuzz has been multiplied by 3.
I'll see if I can make a test in the Image Magick test suite and submit it as a bug.
Danack commentedon Oct 18, 2013
Raised as an issue in Image Magick http://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=24288
Danack commentedon Oct 19, 2013
So, it's not a bug in ImageMagick but:
Pull request has been sent.
Added ImagickPixel::isPixelSimilar and deprecate ImagickPixel::isSimi…
mkoppanen commentedon Oct 30, 2013
This has been resolved
Fix memory leak in Imagick::colorThresholdImage()
Fix memory leak in Imagick::colorThresholdImage()
Fix memory leak in polynomialImage()
Fix memory leak in colorMatrixImage()