-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
[stable25] feat(theming): Only convert a background image if it benefits from it #42943
Conversation
* WebP images are generally quite small, converting to pngs would increase the filesize a lot. * Small JPEG and PNG images do not benefit from any conversion, so skip it. * JPEG images will get quite bigger when converted to PNG so instead convert to progressive JPEG Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
$newHeight = (int)(imagesy($newImage) / (imagesx($newImage) / $newWidth)); | ||
$outputImage = imagescale($newImage, $newWidth, $newHeight); | ||
$newWidth = (int)(imagesx($newImage) < 4096 ? imagesx($newImage) : 4096); | ||
$newHeight = (int)(imagesy($newImage) / (imagesx($newImage) / $newWidth)); |
Check notice
Code scanning / Psalm
PossiblyFalseOperand Note
$newHeight = (int)(imagesy($newImage) / (imagesx($newImage) / $newWidth)); | ||
$outputImage = imagescale($newImage, $newWidth, $newHeight); | ||
$newWidth = (int)(imagesx($newImage) < 4096 ? imagesx($newImage) : 4096); | ||
$newHeight = (int)(imagesy($newImage) / (imagesx($newImage) / $newWidth)); |
Check notice
Code scanning / Psalm
PossiblyFalseOperand Note
imagepng($outputImage, $tmpFile, 8); | ||
imagedestroy($outputImage); | ||
$newTmpFile = $this->tempManager->getTemporaryFile(); | ||
imageinterlace($outputImage, 1); |
Check notice
Code scanning / Psalm
PossiblyInvalidArgument Note
} | ||
} | ||
$tmpFile = $newTmpFile; | ||
imagedestroy($outputImage); |
Check notice
Code scanning / Psalm
PossiblyInvalidArgument Note
$tmpFile = $newTmpFile; | ||
imagedestroy($outputImage); | ||
} catch (\Exception $e) { | ||
if (is_resource($outputImage) || $outputImage instanceof \GdImage) { |
Check notice
Code scanning / Psalm
DocblockTypeContradiction Note
$tmpFile = $newTmpFile; | ||
imagedestroy($outputImage); | ||
} catch (\Exception $e) { | ||
if (is_resource($outputImage) || $outputImage instanceof \GdImage) { |
Check notice
Code scanning / Psalm
DocblockTypeContradiction Note
imagedestroy($outputImage); | ||
} catch (\Exception $e) { | ||
if (is_resource($outputImage) || $outputImage instanceof \GdImage) { | ||
imagedestroy($outputImage); |
Check notice
Code scanning / Psalm
PossiblyInvalidArgument Note
$target->putContent(file_get_contents($tmpFile)); | ||
} else { | ||
$target->putContent(file_get_contents($tmpFile)); | ||
$this->logger->debug($e->getMessage()); |
Check notice
Code scanning / Psalm
DeprecatedMethod Note
imageinterlace($outputImage, 1); | ||
// Keep jpeg images encoded as jpeg | ||
if (strpos($detectedMimeType, 'image/jpeg') !== false) { | ||
if (!imagejpeg($outputImage, $newTmpFile, 90)) { |
Check notice
Code scanning / Psalm
PossiblyInvalidArgument Note
throw new \Exception('Could not recompress background image as JPEG'); | ||
} | ||
} else { | ||
if (!imagepng($outputImage, $newTmpFile, 8)) { |
Check notice
Code scanning / Psalm
PossiblyInvalidArgument Note
Backport of #36471