mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-19 00:22:15 +00:00
controller refactoring part 25
This commit is contained in:
@@ -6,37 +6,46 @@ use Intervention\Image\ImageManagerStatic as Image;
|
||||
|
||||
class CreateImageThumbnailAction
|
||||
{
|
||||
private array $availableFormats = [
|
||||
'image/gif',
|
||||
'image/jpeg',
|
||||
'image/jpg',
|
||||
'image/png',
|
||||
'image/webp'
|
||||
];
|
||||
|
||||
/**
|
||||
* Create image thumbnail from gif, jpeg, jpg, png, webp or svg
|
||||
* Create image thumbnail from uploaded image
|
||||
*/
|
||||
public function __invoke(
|
||||
string $file_path,
|
||||
string $filename,
|
||||
string $user_id
|
||||
): string | null {
|
||||
$availableFormats = ['image/gif', 'image/jpeg', 'image/jpg', 'image/png', 'image/webp'];
|
||||
|
||||
$mimeType = Storage::disk('local')->mimeType($file_path);
|
||||
|
||||
// Create thumbnail from image
|
||||
if (in_array(Storage::disk('local')->mimeType($file_path), $availableFormats)) {
|
||||
if (in_array($mimeType, $this->availableFormats)) {
|
||||
|
||||
// Get thumbnail name
|
||||
$thumbnail = "thumbnail-$filename";
|
||||
|
||||
// Create intervention image
|
||||
$image = Image::make(Storage::disk('local')->path($file_path))
|
||||
$image = Image::make(Storage::disk('local')
|
||||
->path($file_path))
|
||||
->orientate();
|
||||
|
||||
// Resize image
|
||||
$image->resize(512, null, function ($constraint) {
|
||||
$constraint->aspectRatio();
|
||||
})->stream();
|
||||
$image->resize(512, null, fn ($constraint) => $constraint->aspectRatio())->stream();
|
||||
|
||||
// Store thumbnail to disk
|
||||
Storage::put("files/$user_id/$thumbnail", $image);
|
||||
}
|
||||
|
||||
// Return thumbnail as svg file
|
||||
if (Storage::disk('local')->mimeType($file_path) === 'image/svg+xml') {
|
||||
$thumbnail = $filename;
|
||||
if ($mimeType === 'image/svg+xml') {
|
||||
return $filename;
|
||||
}
|
||||
|
||||
return $thumbnail ?? null;
|
||||
|
||||
Reference in New Issue
Block a user