mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-22 09:32:14 +00:00
thumbnail generation refectoring
This commit is contained in:
@@ -16,25 +16,29 @@ class CreateImageThumbnailAcionQueue
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function execute($size, $file_name, $user_id, $is_last)
|
||||
public function execute($file_name, $user_id, $thumnails_sizes)
|
||||
{
|
||||
|
||||
// Get image from disk
|
||||
$image = Storage::disk('local')->get("temp/$user_id/{$file_name}");
|
||||
|
||||
// Create intervention image
|
||||
$intervention = Image::make($image)->orientate();
|
||||
|
||||
// Generate thumbnail
|
||||
$intervention->resize($size['size'], null, fn ($constraint) => $constraint->aspectRatio())->stream();
|
||||
|
||||
// Store thumbnail to disk
|
||||
Storage::put("files/$user_id/{$size['name']}-{$file_name}", $intervention);
|
||||
collect($thumnails_sizes)
|
||||
->each(function ($size) use ($intervention, $user_id, $file_name) {
|
||||
|
||||
if ($is_last) {
|
||||
dd($intervention->getWidth());
|
||||
|
||||
// Delete file after generate a thumbnail
|
||||
Storage::disk('local')->delete("temp/$user_id/{$file_name}");
|
||||
}
|
||||
if ($intervention->getWidth() > $size['size']) {
|
||||
|
||||
// Generate thumbnail
|
||||
$intervention->resize($size['size'], null, fn ($constraint) => $constraint->aspectRatio())->stream();
|
||||
|
||||
// Store thumbnail to disk
|
||||
Storage::put("files/$user_id/{$size['name']}-{$file_name}", $intervention);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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