Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add imagematch() function #14914

wants to merge 1 commit into from

Conversation

thg2k
Copy link
Contributor

@thg2k thg2k commented Jul 11, 2024

This function is a replacement for the missing imagecompare() which does not properly check for transparency of truecolor images.

This function is a replacement for the missing imagecompare() which
does not properly check for transparency of truecolor images.
@thg2k
Copy link
Contributor Author

thg2k commented Jul 11, 2024

This would be a replacement for PR #14877

@pierrejoye
Copy link
Contributor

Hi,

Thanks for this (new) PR :)
Before the relevant part, be sure I do not want to refrain your proposal moving forward :) I prefer to ensure we don't add yet another function not covering what it is supposed to do :)

I am not keen to add that one as is, for several reasons:

  • it should not be implement in the extension but inside libgd
  • it does not do an actual image match, but an pixel values match, which is not what could be expected as it will result in different image formats once saved as well.

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.

@thg2k thg2k mentioned this pull request Dec 30, 2024
2 tasks
Copy link
Member

@cmb69 cmb69 left a 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) \
Copy link
Member

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.

php-src/ext/gd/libgd/gd.h

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;
Copy link
Member

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().

php-src/ext/gd/libgd/gd.h

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;
Copy link
Member

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.

Comment on lines +5 to +8
--SKIPIF--
<?php
if (!(imagetypes() & IMG_PNG)) die("skip No PNG support");
?>
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants