diff --git a/classes/File_thumbnail.php b/classes/File_thumbnail.php index 8290635776..1c31816dc1 100644 --- a/classes/File_thumbnail.php +++ b/classes/File_thumbnail.php @@ -100,8 +100,9 @@ class File_thumbnail extends Managed_DataObject case 'image/svg+xml': throw new UseFileAsThumbnailException($file); } + } else { + throw new ServerException("This remote file has no local thumbnail."); } - throw new ServerException("This remote file has no local thumbnail."); } $image = ImageFile::fromFileObject($file); $imgPath = $image->getPath(); diff --git a/lib/media/attachmentlistitem.php b/lib/media/attachmentlistitem.php index deb447fea1..496e2b2447 100644 --- a/lib/media/attachmentlistitem.php +++ b/lib/media/attachmentlistitem.php @@ -122,13 +122,8 @@ class AttachmentListItem extends Widget try { // Tell getThumbnail that we can show an animated image if it has one (4th arg, "force_still") $thumb = File_thumbnail::fromFileObject($this->attachment, null, null, false, false); - } catch (UseFileAsThumbnailException $e) { - $thumb = null; - } catch (UnsupportedMediaException $e) { - // FIXME: Show a good representation of unsupported/unshowable images - $thumb = null; - } catch (FileNotFoundException $e) { - // Remote file + } catch (UseFileAsThumbnailException|UnsupportedMediaException|FileNotFoundException|ServerException $e) { + // This remote file has no local thumbnail. $thumb = null; } diff --git a/plugins/StoreRemoteMedia/StoreRemoteMediaPlugin.php b/plugins/StoreRemoteMedia/StoreRemoteMediaPlugin.php index 78467fdcfe..864f81ad10 100644 --- a/plugins/StoreRemoteMedia/StoreRemoteMediaPlugin.php +++ b/plugins/StoreRemoteMedia/StoreRemoteMediaPlugin.php @@ -252,17 +252,22 @@ class StoreRemoteMediaPlugin extends Plugin if ($info[0] > $this->thumbnail_width || $info[1] > $this->thumbnail_height) { // Temporary object, not stored in DB $img = new ImageFile(-1, $filepath); - $box = $img->scaleToFit($this->thumbnail_width, $this->thumbnail_height, $this->thumbnail_crop); + // Get proper aspect ratio width and height before lookup + // We have to do it through an ImageFile object because of orientation etc. + // Only other solution would've been to rotate + rewrite uploaded files + // which we don't want to do because we like original, untouched data! + list($width, $height, $x, $y, $w, $h) = $img->scaleToFit($this->thumbnail_width, $this->thumbnail_height, $this->thumbnail_crop); + + // 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']; - $outpath = $img->resizeTo($filepath, $box); - $result = rename($outpath, $filepath); - if (!$result) { - // TRANS: Client exception thrown when a file upload operation fails because the file could - // TRANS: not be moved from the temporary folder to the permanent file location. - // UX: too specific - throw new ClientException(_m('File could not be moved to destination directory.')); - } + $img->resizeTo($filepath, $box); } } else { throw new AlreadyFulfilledException('A thumbnail seems to already exist for remote file' .