From 5b23781e68da086710543e96c53d8a2422bdbd01 Mon Sep 17 00:00:00 2001 From: Diogo Peralta Cordeiro Date: Mon, 12 Apr 2021 03:09:18 +0100 Subject: [PATCH] [StoreRemoteMedia] Gracefully recover from poorly encoded images --- .../StoreRemoteMediaPlugin.php | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/plugins/StoreRemoteMedia/StoreRemoteMediaPlugin.php b/plugins/StoreRemoteMedia/StoreRemoteMediaPlugin.php index b888c46c2e..c5f6399a89 100644 --- a/plugins/StoreRemoteMedia/StoreRemoteMediaPlugin.php +++ b/plugins/StoreRemoteMedia/StoreRemoteMediaPlugin.php @@ -300,20 +300,25 @@ class StoreRemoteMediaPlugin extends Plugin // If the image is not of the desired size, resize it if (!$this->store_original && $this->crop && ($info[0] > $this->thumbnail_width || $info[1] > $this->thumbnail_height)) { - // Temporary object, not stored in DB - $img = new ImageFile(-1, $fullpath); - list($width, $height, $x, $y, $w, $h) = $img->scaleToFit($this->thumbnail_width, $this->thumbnail_height, $this->crop); + try { + // Temporary object, not stored in DB + $img = new ImageFile(-1, $fullpath); + list($width, $height, $x, $y, $w, $h) = $img->scaleToFit($this->thumbnail_width, $this->thumbnail_height, $this->crop); - // The boundary box for our resizing - $box = [ - 'width' => $width, 'height' => $height, - 'x' => $x, 'y' => $y, - 'w' => $w, 'h' => $h, - ]; + // The boundary box for our resizing + $box = [ + 'width' => $width, 'height' => $height, + 'x' => $x, 'y' => $y, + 'w' => $w, 'h' => $h, + ]; - $width = $box['width']; - $height = $box['height']; - $img->resizeTo($fullpath, $box); + $width = $box['width']; + $height = $box['height']; + $img->resizeTo($fullpath, $box); + } catch (\Intervention\Image\Exception\NotReadableException $e) { + common_log(LOG_ERR, "StoreRemoteMediaPlugin::storeRemoteThumbnail was unable to decode image with Intervention: $e"); + // No need to interrupt processing + } } } else { throw new AlreadyFulfilledException('A thumbnail seems to already exist for remote file' .