mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-23 01:32:15 +00:00
thumbnail generation refectoring
This commit is contained in:
@@ -2,14 +2,12 @@
|
||||
namespace Domain\Files\Actions;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Spatie\QueueableAction\QueueableAction;
|
||||
use Intervention\Image\ImageManagerStatic as Image;
|
||||
use Domain\Files\Actions\CreateImageThumbnailAcionQueue;
|
||||
|
||||
|
||||
class CreateImageThumbnailAction
|
||||
{
|
||||
use QueueableAction;
|
||||
|
||||
public function __construct(
|
||||
CreateImageThumbnailAcionQueue $action,
|
||||
@@ -40,44 +38,12 @@ class CreateImageThumbnailAction
|
||||
|
||||
// Make copy of file for the thumbnail generation
|
||||
Storage::disk('local')->copy("files/$user_id/{$file_name}", "temp/$user_id/{$file_name}");
|
||||
|
||||
// Create intervention image
|
||||
$intervention = Image::make($file)->orientate();
|
||||
|
||||
// Generate avatar sizes
|
||||
collect(config('vuefilemanager.image_sizes.execute') )
|
||||
->each(function ($size) use ($intervention, $file_name, $user_id) {
|
||||
// Create thumbnail instantly
|
||||
$this->action->execute($file_name, $user_id, config('vuefilemanager.image_sizes.execute'));
|
||||
|
||||
// Create thumbnail only if image is larger than predefined image sizes
|
||||
if ($intervention->getWidth() > $size['size']) {
|
||||
|
||||
// Create thumbnail instantly
|
||||
$this->action->execute($size, $file_name, $user_id, null);
|
||||
}
|
||||
});
|
||||
|
||||
$last = last(config('vuefilemanager.image_sizes.queue'));
|
||||
|
||||
collect(config('vuefilemanager.image_sizes.queue'))
|
||||
->each(function ($size) use ($intervention, $file_name, $user_id, $last) {
|
||||
|
||||
$is_last = $last['size'] === $size['size'] ? true : false;
|
||||
|
||||
// Create thumbnail only if image is larger than predefined image sizes
|
||||
if ($intervention->getWidth() > $size['size']) {
|
||||
|
||||
// Create thumbnail queue job
|
||||
$this->action->onQueue()->execute($size, $file_name, $user_id, $is_last);
|
||||
|
||||
} else {
|
||||
|
||||
// Delete file after generate a thumbnail
|
||||
Storage::disk('local')->delete("temp/$user_id/{$file_name}");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
// Create thumbnail queue job
|
||||
$this->action->onQueue()->execute($file_name, $user_id, config('vuefilemanager.image_sizes.queue'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user