Skip to content

Commit

Permalink
Merge pull request #28485 from nextcloud/bugfix/20913/check-image-res…
Browse files Browse the repository at this point in the history
…ource

Fix #20913: Check image resource before attempting to preserve alpha
  • Loading branch information
juliusknorr authored Aug 18, 2021
2 parents 95987d9 + 58f5597 commit bccdd32
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 @@ -562,9 +562,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 @@ -583,9 +587,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 bccdd32

Please sign in to comment.