Add imagematch() function#14914
Conversation
This function is a replacement for the missing imagecompare() which does not properly check for transparency of truecolor images.
|
This would be a replacement for PR #14877 |
|
Hi, Thanks for this (new) PR :) I am not keen to add that one as is, for several reasons:
I would rather do something like what has been discussed in the other PR, how it is exposed in php can be provided through different functions (bool result for exact match or detailed diff comparison f.e.) Maybe we can also continue to discuss the implementation details in the other PR as it has all the history and details. |
cmb69
left a comment
There was a problem hiding this comment.
I prefer to ensure we don't add yet another function not covering what it is supposed to do :)
Good point!
it should not be implement in the extension but inside libgd
I don't necessarily agree. Any complex function should likely be implemented in libgd, but a simple function would not make much sense there (users could easily implement that in C themselves). And such simple functions would only need to be implemented in C for performance reasons (if these are valid, i.e. plain PHP would be considerably slower), in which case implementing them in the libgd bindings might make sense.
| } | ||
| /* }}} */ | ||
|
|
||
| #define GET_TRUECOLOR_PIXEL(px, im, x, y) \ |
There was a problem hiding this comment.
I think we could use gdImageRed() and friends instead. Shouldn't make much of a performance difference.
Lines 771 to 778 in 6fb79e2
| im1 = php_gd_libgdimageptr_from_zval_p(IM1); | ||
| im2 = php_gd_libgdimageptr_from_zval_p(IM2); | ||
|
|
||
| sx = im1->sx; |
There was a problem hiding this comment.
Probably better to use gdImageSX() and gdImageSY().
Lines 768 to 769 in 6fb79e2
| GET_TRUECOLOR_PIXEL(p2, im2, x, y); | ||
|
|
||
| if (p1 != p2) { | ||
| result = false; |
There was a problem hiding this comment.
If we're only interested in a bool return value, we could return here. It might be useful to have an int return, though, which reports how many pixels are different.
| --SKIPIF-- | ||
| <?php | ||
| if (!(imagetypes() & IMG_PNG)) die("skip No PNG support"); | ||
| ?> |
There was a problem hiding this comment.
Since there is no PNG involved, this section can be dropped.
|
See #22532 it adds the perceptual APIs in libgd/ |
This function is a replacement for the missing imagecompare() which does not properly check for transparency of truecolor images.