Skip to content

Commit

Permalink
Fix #20913: Check image resource before attempting to preserve alpha
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Spannagel <[email protected]>
  • Loading branch information
Simon Spannagel authored and backportbot[bot] committed Aug 18, 2021
1 parent df87216 commit cb9e9f3
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions lib/private/legacy/OC_Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -563,9 +563,13 @@ public function loadFromFile($imagePath = false) {
case IMAGETYPE_GIF:
if (imagetypes() & IMG_GIF) {
$this->resource = imagecreatefromgif($imagePath);
// Preserve transparency
imagealphablending($this->resource, true);
imagesavealpha($this->resource, true);
if ($this->resource) {
// Preserve transparency
imagealphablending($this->resource, true);
imagesavealpha($this->resource, true);
} else {
$this->logger->debug('OC_Image->loadFromFile, GIF image not valid: ' . $imagePath, ['app' => 'core']);
}
} else {
$this->logger->debug('OC_Image->loadFromFile, GIF images not supported: ' . $imagePath, ['app' => 'core']);
}
Expand All @@ -584,9 +588,13 @@ public function loadFromFile($imagePath = false) {
case IMAGETYPE_PNG:
if (imagetypes() & IMG_PNG) {
$this->resource = @imagecreatefrompng($imagePath);
// Preserve transparency
imagealphablending($this->resource, true);
imagesavealpha($this->resource, true);
if ($this->resource) {
// Preserve transparency
imagealphablending($this->resource, true);
imagesavealpha($this->resource, true);
} else {
$this->logger->debug('OC_Image->loadFromFile, PNG image not valid: ' . $imagePath, ['app' => 'core']);
}
} else {
$this->logger->debug('OC_Image->loadFromFile, PNG images not supported: ' . $imagePath, ['app' => 'core']);
}
Expand Down

0 comments on commit cb9e9f3

Please sign in to comment.