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

[stable25] feat(theming): Only convert a background image if it benefits from it #42943

Merged
merged 3 commits into from
Jan 19, 2024

Conversation

backportbot-nextcloud[bot]
Copy link

Backport of #36471

* 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

Left operand cannot be falsable, got false|int
$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

Left operand cannot be falsable, got false|int
imagepng($outputImage, $tmpFile, 8);
imagedestroy($outputImage);
$newTmpFile = $this->tempManager->getTemporaryFile();
imageinterlace($outputImage, 1);

Check notice

Code scanning / Psalm

PossiblyInvalidArgument Note

Argument 1 of imageinterlace expects resource, possibly different type resource|true provided
}
}
$tmpFile = $newTmpFile;
imagedestroy($outputImage);

Check notice

Code scanning / Psalm

PossiblyInvalidArgument Note

Argument 1 of imagedestroy expects resource, possibly different type resource|true provided
$tmpFile = $newTmpFile;
imagedestroy($outputImage);
} catch (\Exception $e) {
if (is_resource($outputImage) || $outputImage instanceof \GdImage) {

Check notice

Code scanning / Psalm

DocblockTypeContradiction Note

Cannot resolve types for $outputImage - docblock-defined type resource|true does not contain GdImage
$tmpFile = $newTmpFile;
imagedestroy($outputImage);
} catch (\Exception $e) {
if (is_resource($outputImage) || $outputImage instanceof \GdImage) {

Check notice

Code scanning / Psalm

DocblockTypeContradiction Note

Cannot resolve types for $outputImage - docblock-defined type true does not contain GdImage
imagedestroy($outputImage);
} catch (\Exception $e) {
if (is_resource($outputImage) || $outputImage instanceof \GdImage) {
imagedestroy($outputImage);

Check notice

Code scanning / Psalm

PossiblyInvalidArgument Note

Argument 1 of imagedestroy expects resource, possibly different type GdImage|resource provided
$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

The method OCP\ILogger::debug has been marked as deprecated
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

Argument 1 of imagejpeg expects resource, possibly different type resource|true provided
throw new \Exception('Could not recompress background image as JPEG');
}
} else {
if (!imagepng($outputImage, $newTmpFile, 8)) {

Check notice

Code scanning / Psalm

PossiblyInvalidArgument Note

Argument 1 of imagepng expects resource, possibly different type resource|true provided
@susnux susnux merged commit 45a16bf into stable25 Jan 19, 2024
29 of 30 checks passed
@susnux susnux deleted the backport/36471/stable25 branch January 19, 2024 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants