forked from GNUsocial/gnu-social
[StoreRemoteMedia] Remote images are now stored exactly on the necessary size for the thumb
This commit is contained in:
parent
22b5dd8567
commit
ef0f65720e
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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' .
|
||||
|
Loading…
Reference in New Issue
Block a user