Skip to content

Commit

Permalink
Merge pull request #32622 from nextcloud/backport/32601/stable23
Browse files Browse the repository at this point in the history
[stable23] Move Gd failed operations to debug level
  • Loading branch information
nickvergessen committed May 27, 2022
2 parents 087140b + bd739bc commit e89730c
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions lib/private/legacy/OC_Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,8 @@ public function __construct($imageRef = null, \OCP\ILogger $logger = null, \OCP\
* @return bool
*/
public function valid() {
if (is_resource($this->resource)) {
return true;
}
if (is_object($this->resource) && get_class($this->resource) === \GdImage::class) {
if ((is_resource($this->resource) && get_resource_type($this->resource) === 'gd') ||
(is_object($this->resource) && get_class($this->resource) === \GdImage::class)) {
return true;
}

Expand Down Expand Up @@ -486,7 +484,7 @@ public function readExif($data) {
*/
public function fixOrientation() {
if (!$this->valid()) {
$this->logger->error(__METHOD__ . '(): No image loaded', ['app' => 'core']);
$this->logger->debug(__METHOD__ . '(): No image loaded', ['app' => 'core']);
return false;
}
$o = $this->getOrientation();
Expand Down Expand Up @@ -994,7 +992,7 @@ private function imagecreatefrombmp($fileName) {
*/
public function resize($maxSize) {
if (!$this->valid()) {
$this->logger->error(__METHOD__ . '(): No image loaded', ['app' => 'core']);
$this->logger->debug(__METHOD__ . '(): No image loaded', ['app' => 'core']);
return false;
}
$result = $this->resizeNew($maxSize);
Expand All @@ -1009,7 +1007,7 @@ public function resize($maxSize) {
*/
private function resizeNew($maxSize) {
if (!$this->valid()) {
$this->logger->error(__METHOD__ . '(): No image loaded', ['app' => 'core']);
$this->logger->debug(__METHOD__ . '(): No image loaded', ['app' => 'core']);
return false;
}
$widthOrig = imagesx($this->resource);
Expand All @@ -1034,7 +1032,7 @@ private function resizeNew($maxSize) {
*/
public function preciseResize(int $width, int $height): bool {
if (!$this->valid()) {
$this->logger->error(__METHOD__ . '(): No image loaded', ['app' => 'core']);
$this->logger->debug(__METHOD__ . '(): No image loaded', ['app' => 'core']);
return false;
}
$result = $this->preciseResizeNew($width, $height);
Expand All @@ -1055,14 +1053,14 @@ public function preciseResizeNew(int $width, int $height) {
return false;
}
if (!$this->valid()) {
$this->logger->error(__METHOD__ . '(): No image loaded', ['app' => 'core']);
$this->logger->debug(__METHOD__ . '(): No image loaded', ['app' => 'core']);
return false;
}
$widthOrig = imagesx($this->resource);
$heightOrig = imagesy($this->resource);
$process = imagecreatetruecolor($width, $height);
if ($process === false) {
$this->logger->error(__METHOD__ . '(): Error creating true color image', ['app' => 'core']);
$this->logger->debug(__METHOD__ . '(): Error creating true color image', ['app' => 'core']);
return false;
}

Expand All @@ -1075,7 +1073,7 @@ public function preciseResizeNew(int $width, int $height) {

$res = imagecopyresampled($process, $this->resource, 0, 0, 0, 0, $width, $height, $widthOrig, $heightOrig);
if ($res === false) {
$this->logger->error(__METHOD__ . '(): Error re-sampling process image', ['app' => 'core']);
$this->logger->debug(__METHOD__ . '(): Error re-sampling process image', ['app' => 'core']);
imagedestroy($process);
return false;
}
Expand All @@ -1090,7 +1088,7 @@ public function preciseResizeNew(int $width, int $height) {
*/
public function centerCrop($size = 0) {
if (!$this->valid()) {
$this->logger->error('OC_Image->centerCrop, No image loaded', ['app' => 'core']);
$this->logger->debug('OC_Image->centerCrop, No image loaded', ['app' => 'core']);
return false;
}
$widthOrig = imagesx($this->resource);
Expand All @@ -1117,7 +1115,7 @@ public function centerCrop($size = 0) {
}
$process = imagecreatetruecolor($targetWidth, $targetHeight);
if ($process === false) {
$this->logger->error('OC_Image->centerCrop, Error creating true color image', ['app' => 'core']);
$this->logger->debug('OC_Image->centerCrop, Error creating true color image', ['app' => 'core']);
return false;
}

Expand All @@ -1130,7 +1128,7 @@ public function centerCrop($size = 0) {

imagecopyresampled($process, $this->resource, 0, 0, $x, $y, $targetWidth, $targetHeight, $width, $height);
if ($process === false) {
$this->logger->error('OC_Image->centerCrop, Error re-sampling process image ' . $width . 'x' . $height, ['app' => 'core']);
$this->logger->debug('OC_Image->centerCrop, Error re-sampling process image ' . $width . 'x' . $height, ['app' => 'core']);
return false;
}
imagedestroy($this->resource);
Expand All @@ -1149,7 +1147,7 @@ public function centerCrop($size = 0) {
*/
public function crop(int $x, int $y, int $w, int $h): bool {
if (!$this->valid()) {
$this->logger->error(__METHOD__ . '(): No image loaded', ['app' => 'core']);
$this->logger->debug(__METHOD__ . '(): No image loaded', ['app' => 'core']);
return false;
}
$result = $this->cropNew($x, $y, $w, $h);
Expand All @@ -1169,12 +1167,12 @@ public function crop(int $x, int $y, int $w, int $h): bool {
*/
public function cropNew(int $x, int $y, int $w, int $h) {
if (!$this->valid()) {
$this->logger->error(__METHOD__ . '(): No image loaded', ['app' => 'core']);
$this->logger->debug(__METHOD__ . '(): No image loaded', ['app' => 'core']);
return false;
}
$process = imagecreatetruecolor($w, $h);
if ($process === false) {
$this->logger->error(__METHOD__ . '(): Error creating true color image', ['app' => 'core']);
$this->logger->debug(__METHOD__ . '(): Error creating true color image', ['app' => 'core']);
return false;
}

Expand All @@ -1187,7 +1185,7 @@ public function cropNew(int $x, int $y, int $w, int $h) {

imagecopyresampled($process, $this->resource, 0, 0, $x, $y, $w, $h, $w, $h);
if ($process === false) {
$this->logger->error(__METHOD__ . '(): Error re-sampling process image ' . $w . 'x' . $h, ['app' => 'core']);
$this->logger->debug(__METHOD__ . '(): Error re-sampling process image ' . $w . 'x' . $h, ['app' => 'core']);
return false;
}
return $process;
Expand All @@ -1204,7 +1202,7 @@ public function cropNew(int $x, int $y, int $w, int $h) {
*/
public function fitIn($maxWidth, $maxHeight) {
if (!$this->valid()) {
$this->logger->error(__METHOD__ . '(): No image loaded', ['app' => 'core']);
$this->logger->debug(__METHOD__ . '(): No image loaded', ['app' => 'core']);
return false;
}
$widthOrig = imagesx($this->resource);
Expand All @@ -1227,7 +1225,7 @@ public function fitIn($maxWidth, $maxHeight) {
*/
public function scaleDownToFit($maxWidth, $maxHeight) {
if (!$this->valid()) {
$this->logger->error(__METHOD__ . '(): No image loaded', ['app' => 'core']);
$this->logger->debug(__METHOD__ . '(): No image loaded', ['app' => 'core']);
return false;
}
$widthOrig = imagesx($this->resource);
Expand Down

0 comments on commit e89730c

Please sign in to comment.