forked from mirror/pixelfed
Update thumbnail logic
This commit is contained in:
parent
4794182334
commit
84d1e3b731
|
@ -13,6 +13,10 @@ class Image
|
||||||
public $portrait;
|
public $portrait;
|
||||||
public $thumbnail;
|
public $thumbnail;
|
||||||
public $orientation;
|
public $orientation;
|
||||||
|
public $acceptedMimes = [
|
||||||
|
'image/png',
|
||||||
|
'image/jpeg',
|
||||||
|
];
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
@ -22,8 +26,8 @@ class Image
|
||||||
$this->landscape = $this->orientations()['landscape'];
|
$this->landscape = $this->orientations()['landscape'];
|
||||||
$this->portrait = $this->orientations()['portrait'];
|
$this->portrait = $this->orientations()['portrait'];
|
||||||
$this->thumbnail = [
|
$this->thumbnail = [
|
||||||
'width' => 293,
|
'width' => 640,
|
||||||
'height' => 293,
|
'height' => 640,
|
||||||
];
|
];
|
||||||
$this->orientation = null;
|
$this->orientation = null;
|
||||||
}
|
}
|
||||||
|
@ -98,18 +102,22 @@ class Image
|
||||||
{
|
{
|
||||||
$path = $media->media_path;
|
$path = $media->media_path;
|
||||||
$file = storage_path('app/'.$path);
|
$file = storage_path('app/'.$path);
|
||||||
|
if (!in_array($media->mime, $this->acceptedMimes)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
$ratio = $this->getAspectRatio($file, $thumbnail);
|
$ratio = $this->getAspectRatio($file, $thumbnail);
|
||||||
$aspect = $ratio['dimensions'];
|
$aspect = $ratio['dimensions'];
|
||||||
$orientation = $ratio['orientation'];
|
$orientation = $ratio['orientation'];
|
||||||
if ($media->mime === 'image/gif' && !$thumbnail) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$img = Intervention::make($file)->orientate();
|
$img = Intervention::make($file)->orientate();
|
||||||
|
if($thumbnail) {
|
||||||
|
$img->crop($aspect['width'], $aspect['height']);
|
||||||
|
} else {
|
||||||
$img->resize($aspect['width'], $aspect['height'], function ($constraint) {
|
$img->resize($aspect['width'], $aspect['height'], function ($constraint) {
|
||||||
$constraint->aspectRatio();
|
$constraint->aspectRatio();
|
||||||
});
|
});
|
||||||
|
}
|
||||||
$converted = $this->setBaseName($path, $thumbnail, $img->extension);
|
$converted = $this->setBaseName($path, $thumbnail, $img->extension);
|
||||||
$newPath = storage_path('app/'.$converted['path']);
|
$newPath = storage_path('app/'.$converted['path']);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue