Skip to content

Conversation

@adamsilverstein
Copy link
Contributor

Originally #327

Lossless WebP is a rather interesting alternative to PNG, and already
supported by gdImageCreateFromWebp*(), so we add support for
gdImageWebp*(), too.

We can stick with the existing API, using the quality parameter to
request lossless encoding if it is set to gdWebpLossless, which we
define to PHP_INT (to avoid adding a new dependency to gd.h, we hard-
code the value – we're assuming sizeof(int)==4 anyway).

cmb69 and others added 3 commits October 9, 2016 00:47
Lossless WebP is a rather interesting alternative to PNG, and already
supported by `gdImageCreateFromWebp*()`, so we add support for
`gdImageWebp*()`, too.

We can stick with the existing API, using the quality parameter to
request lossless encoding if it is set to `gdWebpLossless`, which we
define to `PHP_INT` (to avoid adding a new dependency to gd.h, we hard-
code the value – we're assuming `sizeof(int)==4` anyway).
# Conflicts:
#	tests/webp/.gitignore
#	tests/webp/CMakeLists.txt
#	tests/webp/Makemodule.am
@adamsilverstein
Copy link
Contributor Author

@cmb69 I'm going to test this out in WordPress, can you confirm that for previous versions of libgd, if I pass a quality value of 101 to imagewebp will it use 100 instead (or would I get an error)?

adamsilverstein added a commit to adamsilverstein/wordpress-develop that referenced this pull request May 5, 2021
adamsilverstein added a commit to adamsilverstein/wordpress-develop that referenced this pull request May 5, 2021
adamsilverstein added a commit to adamsilverstein/wordpress-develop that referenced this pull request May 5, 2021
@cmb69
Copy link
Member

cmb69 commented May 5, 2021

The quality is passed to WebPEncodeRGBA(); not sure how that function handles out of range values.

@cmb69
Copy link
Member

cmb69 commented May 6, 2021

Thank you!

There is a caveat, though: WebPEncodeLosslessRGBA() is only available as of libwebp 1.2.0, but we do not require any particular libwebp version so far. Either we raise the requirements, or we must use WebPEncodeLosslessRGBA() only if available.

@vapier
Copy link
Member

vapier commented May 6, 2021

libwebp-1.2.0 was only released a few months ago, so we can't require it :/

@cmb69
Copy link
Member

cmb69 commented May 6, 2021

Sorry, I've been confused by the GH UI. Actually, it should be available as of 0.2.0, released 2012.

@adamsilverstein
Copy link
Contributor Author

Sorry, I've been confused by the GH UI. Actually, it should be available as of 0.2.0, released 2012.

So does that mean the code is ok as is, or are there additional changes needed?

I'll look into WebPEncodeRGBA, I can't tell from the code, but I can try testing it with WordPress to see how it behaves. I just want to be sure passing 101 to an older version of GD won't break anything, otherwise we would need to check the GD version before using the feature.

@cmb69
Copy link
Member

cmb69 commented May 11, 2021

I'm not sure whether not supporting <= 0.1 is an issue; might be okay to just document that fact. Of course, it would be better to check during configure that libwebp >= 0.2 is available, and likely still better to check that WebPEncodeRGBA() is available.

The quality is passed to WebPEncodeRGBA(); not sure how that function handles out of range values.

I still don't know. Better test it. :)

@adamsilverstein
Copy link
Contributor Author

it would be better to check during configure that libwebp >= 0.2 is available, and likely still better to check that WebPEncodeRGBA() is available

I'll see if I can figure out how to add that in configure, thanks for the lead. hopefully I can find a similar capability check already in use for some other part.

@cmb69
Copy link
Member

cmb69 commented May 11, 2021

I'll see if I can figure out how to add that in configure, thanks for the lead. hopefully I can find a similar capability check already in use for some other part.

See, for instance,

libgd/CMakeLists.txt

Lines 128 to 133 in 82d2609

IF (ENABLE_AVIF)
FIND_PACKAGE(libavif 0.8.2 REQUIRED CONFIG)
SET(HAVE_LIBAVIF 1)
SET(AVIF_LIBRARIES avif)
SET(AVIF_FOUND 1)
ENDIF (ENABLE_AVIF)

Note that GD also has an autotools build chain, which also needs respective checkks. I think we can ignore the Windows build chains (at least for now).

@morsssss
Copy link
Contributor

If it helps, we did some similar version checking in the avif PR.

@adamsilverstein
Copy link
Contributor Author

Of course, it would be better to check during configure that libwebp >= 0.2 is available

To clarify - do you mean adding that as a requirement in the existing ENABLE_WEBP check, or adding a new check that sets something like ENABLE_WEBP_LOSSLESS?

@vapier
Copy link
Member

vapier commented May 12, 2021

requiring libwebp 0.2.0 is fine, so just make it the min version all the time and call it a day

@adamsilverstein
Copy link
Contributor Author

I took a pass, however I am working pretty blindly here - meaning I'm not sure what I am doing 🤷🏼 😄 . I question if this change works because I tried higher version number and configure/make still worked for me locally.

@cmb69
Copy link
Member

cmb69 commented May 13, 2021

Did you run bootstrap.sh?

@adamsilverstein
Copy link
Contributor Author

Did you run bootstrap.sh?

Aha!

@pierrejoye
Copy link
Contributor

good morning :)

Thanks for this PR!

anything left here? Need support?

@morsssss
Copy link
Contributor

@adamsilverstein , @pierrejoye , it strikes me that we should port this change over to PHP right away. I don't know if we'll get it in before feature freeze, which is tomorrow, but it's worth a try...

https://wiki.php.net/todo/php81

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.

In my opinion, this is still good for PHP-8.1 even after feature freeze (should happen before ABI freeze, though).

@morsssss
Copy link
Contributor

In my opinion, this is still good for PHP-8.1 even after feature freeze (should happen before ABI freeze, though).

what is ABI freeze? (I see the next milestone looks like Beta 1 on 22 July)

@cmb69
Copy link
Member

cmb69 commented Jul 19, 2021

what is ABI freeze?

That would be tagging of RC1 (Aug, 31st)

@morsssss
Copy link
Contributor

On the libgd side... is this ready to merge?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants