-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add imagematch() function #14914
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -3254,6 +3254,63 @@ PHP_FUNCTION(imagecopyresized) | |||
} | |||
/* }}} */ | |||
|
|||
#define GET_TRUECOLOR_PIXEL(px, im, x, y) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could use gdImageRed()
and friends instead. Shouldn't make much of a performance difference.
Lines 771 to 778 in 6fb79e2
#define gdImageRed(im, c) ((im)->trueColor ? gdTrueColorGetRed(c) : \ | |
(im)->red[(c)]) | |
#define gdImageGreen(im, c) ((im)->trueColor ? gdTrueColorGetGreen(c) : \ | |
(im)->green[(c)]) | |
#define gdImageBlue(im, c) ((im)->trueColor ? gdTrueColorGetBlue(c) : \ | |
(im)->blue[(c)]) | |
#define gdImageAlpha(im, c) ((im)->trueColor ? gdTrueColorGetAlpha(c) : \ | |
(im)->alpha[(c)]) |
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably better to use gdImageSX()
and gdImageSY()
.
Lines 768 to 769 in 6fb79e2
#define gdImageSX(im) ((im)->sx) | |
#define gdImageSY(im) ((im)->sy) |
GET_TRUECOLOR_PIXEL(p2, im2, x, y); | ||
|
||
if (p1 != p2) { | ||
result = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there is no PNG involved, this section can be dropped.
This function is a replacement for the missing imagecompare() which does not properly check for transparency of truecolor images.