i working on simple script calculates fingerprint of image file detect resized copies of same images (and copies in different format). works pretty fine, except access image color values need read every single pixel of image using imagecolorat() this:
function image_chksum (&$src_image, $x1, $y1, $x2, $y2) { $chksum = 0; ($x = $x1; $x < $x2; $x++) ($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 does, not whole algorithm, it's example)
so. looking @ ugly code question comes - can access gd image resource ($src_image in case) , use array or someth. i've seen method working in python using pil/pillow.
this problem appears when checking alpha png images. unfortunately methods described here: how check png grayscale/alpha color type? not work non-truecolor images, have fallback checking every single pixel (again). first-in-mind idea check every n-th pixel, because transparency used in areas, not single pixels, that's uncool.
the qb extension might solution you're looking for. lets access gd image multidimensional array. depending on more convenient, may declare image either array of uint8[4], each pixel array of 4 8-bit integer, or array of float32[4], each pixel array of 4 32-bit floating point numbers, (with values between 0 , 1).
performance should @ least 1 order of magnitude better regular php. enabling native compilation makes code run 5 times faster still.
Comments
Post a Comment