I am working on a simple script which calculates a fingerprint of an image file to detect resized copies of same images (and copies in different format).
Everything works pretty fine, except that to access image color values i need to read every single pixel of an image using imagecolorat()
like this:
function image_chksum (&$src_image, $x1, $y1, $x2, $y2) {
$chksum = 0;
for ($x = $x1; $x < $x2; $x++)
for ($y = $y1; $y < $y2; $y++) {
$rgb = imagecolorsforindex ($src_image, imagecolorat($src_image, $x, $y));
$sum = ($rgb["red"] + $rgb["green"] + $rgb["blue"] + $rgb["alpha"]);
$chksum += $sum;
}
return $chksum;
}
(Don't pay attention to what it does, this is not the whole algorithm, it's just an example)
So. looking at this ugly code a question comes up - can i just access a gd image resource ($src_image
in my case) and use it as an array or someth.
I've seen this method working in python using PIL/PILLOW.
This problem also appears when checking for alpha png images. Unfortunately methods described here: How to check a PNG for grayscale/alpha color type? does not work for non-truecolor images, so i have to fallback to checking every single pixel (again). A first-in-mind idea is to check every N-th pixel, because transparency is usually used in areas, not single pixels, but that's very uncool.