-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Use highest quality for JPEG and PNG images #2318
Conversation
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.
👍
468da54
to
8c641e4
Compare
@MegaChriz, I pushed the changes I had in mind. Would you mind testing that it still behave as you expect, please ? |
8c641e4
to
27b6500
Compare
@PowerKiKi Great! I plan to test it this Wednesday. |
src/PhpWord/Element/Image.php
Outdated
$this->imageExtension = 'png'; | ||
$this->imageQuality = 0; |
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.
PNG $quality is the zlib compression level, it is a lossless value. $filters is what enables any lossy compression but it is disabled by default. Setting PNG quality to 0 disables all compression resulting in larger files with no quality benefit.
The default for https://www.php.net/imagepng is -1 which in-turn defaults to the zlib compression default which from the zlib documentation is a quality value of 6
The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: 1 gives best speed, 9 gives best compression, 0 gives no compression at all (the input data is simply copied a block at a time). Z_DEFAULT_COMPRESSION requests a default compromise between speed and compression (currently equivalent to level 6).
Suggest changing the PNG quality value to -1 not 0 in this patch.
af66917
to
1afcaab
Compare
This sets the quality of JPEG files to their maximum. It does this by: - defining a property called `$imageQuality` and a method called `getImageQuality()` to PhpOffice\PhpWord\Element\Image - setting the property `$imageQuality` to `100` for JPG, but keep default compression level for PNG - refactor fragile string callbacks into proper closure that use the new `$imageQuality` In the case of a PNG, this is not the _quality_ of the image, but the _filesize_ of the image. So we use the default value for best speed/filesize balance.
1afcaab
to
bc3476b
Compare
Released as 1.1.0 |
Description
This sets the quality of JPEG and PNG files to their maximum. It does this by:
$imageQuality
and a method calledgetImageQuality()
to PhpOffice\PhpWord\Element\Image;$imageQuality
to100
in case of image/jpeg or image/jpg and set it to0
in case of image/png;I also added test coverage for PhpOffice\PhpWord\Element\Image::getImageQuality().
Fixes #2317
Checklist:
composer run-script check --timeout=0
and no errors were reported