Skip to content

fix ImageManager::compressUntilSize() - #2200

Open
blued-gear wants to merge 4 commits into
mainfrom
fix/compress_until_size
Open

fix ImageManager::compressUntilSize()#2200
blued-gear wants to merge 4 commits into
mainfrom
fix/compress_until_size

Conversation

@blued-gear

Copy link
Copy Markdown
Collaborator

The loop checks if the compression had any effect, but it does so with the original file size. If the image got compressed in the first iteration, the condition then would always be false.

Comment thread src/Service/ImageManager.php Outdated
public function compressUntilSize(string $filePath, string $extension, int $maxBytes): bool
{
if (-1 === $this->imageCompressionQuality || filesize($filePath) <= $maxBytes) {
if (-1 === (int)$this->imageCompressionQuality || filesize($filePath) <= $maxBytes) {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

IDE showed me that this comparison would always fail as -1 is an int and imageCompressionQuality is a float

$quality = $this->imageCompressionQuality;
}
while ($bytes > $maxBytes && $quality > 0.1) {
while ($bytes > $maxBytes && $quality > 0.3) {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I changed it to 0.3 to shorten the loop. IMO even at this quality level the images would be well fried already.

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.

1 participant