Skip to content

Commit 160dfbb

Browse files
authored
Merge pull request #28498 from nextcloud/backport/28485/stable21
[stable21] Fix #20913: Check image resource before attempting to preserve alpha
2 parents a53e280 + cb9e9f3 commit 160dfbb

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

lib/private/legacy/OC_Image.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -563,9 +563,13 @@ public function loadFromFile($imagePath = false) {
563563
case IMAGETYPE_GIF:
564564
if (imagetypes() & IMG_GIF) {
565565
$this->resource = imagecreatefromgif($imagePath);
566-
// Preserve transparency
567-
imagealphablending($this->resource, true);
568-
imagesavealpha($this->resource, true);
566+
if ($this->resource) {
567+
// Preserve transparency
568+
imagealphablending($this->resource, true);
569+
imagesavealpha($this->resource, true);
570+
} else {
571+
$this->logger->debug('OC_Image->loadFromFile, GIF image not valid: ' . $imagePath, ['app' => 'core']);
572+
}
569573
} else {
570574
$this->logger->debug('OC_Image->loadFromFile, GIF images not supported: ' . $imagePath, ['app' => 'core']);
571575
}
@@ -584,9 +588,13 @@ public function loadFromFile($imagePath = false) {
584588
case IMAGETYPE_PNG:
585589
if (imagetypes() & IMG_PNG) {
586590
$this->resource = @imagecreatefrompng($imagePath);
587-
// Preserve transparency
588-
imagealphablending($this->resource, true);
589-
imagesavealpha($this->resource, true);
591+
if ($this->resource) {
592+
// Preserve transparency
593+
imagealphablending($this->resource, true);
594+
imagesavealpha($this->resource, true);
595+
} else {
596+
$this->logger->debug('OC_Image->loadFromFile, PNG image not valid: ' . $imagePath, ['app' => 'core']);
597+
}
590598
} else {
591599
$this->logger->debug('OC_Image->loadFromFile, PNG images not supported: ' . $imagePath, ['app' => 'core']);
592600
}

0 commit comments

Comments
 (0)