Skip to content
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

feat: GDHandler make WebP with option quality #7506

Merged
merged 7 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion system/Images/Handlers/GDHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public function save(?string $target = null, int $quality = 90): bool
throw ImageException::forInvalidImageCreate(lang('Images.webpNotSupported'));
}

if (! @imagewebp($this->resource, $target)) {
if (! @imagewebp($this->resource, $target, $quality)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR changes the default quality from -1 to 90.
https://www.php.net/manual/en/function.imagewebp.php#refsect1-function.imagewebp-description
I don't know what -1 means.
Does this degrade the image quality?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably the same as in imagejpeg() - https://www.php.net/manual/en/function.imagejpeg.php

The default (-1) uses the default IJG quality value (about 75).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it appears to be a fixed value.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the behavior changes (80 -> 90), should we add this to changelog?
This doesn't seem to destroy the application, though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we must change default $quality to 80, And i can set parameter $quality to PNG with 0 - 9.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean that the default quality for webp is 80, for jpeg is 90?

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 should stay with 90 as the default value for quality. Having a separate value for WEBP makes not much sense to me.

Regarding PNG, we can't speak about the quality since these files are lossless. The image quality, as we know it from JPEG or WEBP, will not be changed. Only the compression - file size will be changed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its okay, i agree to $quality to WebP using default 90. And with this changes make developer have preferences to changes quality compression for WebP

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throw ImageException::forSaveFailed();
}
break;
Expand Down
2 changes: 1 addition & 1 deletion user_guide_src/source/libraries/images.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Image Quality

``save()`` can take an additional parameter ``$quality`` to alter the resulting image
quality. Values range from 0 to 100 with 90 being the framework default. This parameter
only applies to JPEG images and will be ignored otherwise:
only applies to JPEG and WEBP images, will be ignored otherwise:
kenjis marked this conversation as resolved.
Show resolved Hide resolved

.. literalinclude:: images/005.php

Expand Down