mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-05-21 12:35:01 +00:00
thumbnail generation refectoring
This commit is contained in:
@@ -1140,7 +1140,10 @@ class SetupDevEnvironment extends Command
|
|||||||
$this->info("Generating thumbnails for $file...");
|
$this->info("Generating thumbnails for $file...");
|
||||||
|
|
||||||
// Generate avatar sizes
|
// Generate avatar sizes
|
||||||
collect(array_merge(config('vuefilemanager.image_sizes.queue'), config('vuefilemanager.image_sizes.execute')))
|
collect([
|
||||||
|
config('vuefilemanager.image_sizes.queue'),
|
||||||
|
config('vuefilemanager.image_sizes.execute'),
|
||||||
|
])->collapse()
|
||||||
->each(function ($size) use ($intervention, $file_name, $user) {
|
->each(function ($size) use ($intervention, $file_name, $user) {
|
||||||
// Create thumbnail only if image is larger than predefined image sizes
|
// Create thumbnail only if image is larger than predefined image sizes
|
||||||
if ($intervention->getWidth() > $size['size']) {
|
if ($intervention->getWidth() > $size['size']) {
|
||||||
|
|||||||
@@ -16,25 +16,29 @@ class CreateImageThumbnailAcionQueue
|
|||||||
*
|
*
|
||||||
* @return mixed
|
* @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
|
// Get image from disk
|
||||||
$image = Storage::disk('local')->get("temp/$user_id/{$file_name}");
|
$image = Storage::disk('local')->get("temp/$user_id/{$file_name}");
|
||||||
|
|
||||||
// Create intervention image
|
// Create intervention image
|
||||||
$intervention = Image::make($image)->orientate();
|
$intervention = Image::make($image)->orientate();
|
||||||
|
|
||||||
// Generate thumbnail
|
collect($thumnails_sizes)
|
||||||
$intervention->resize($size['size'], null, fn ($constraint) => $constraint->aspectRatio())->stream();
|
->each(function ($size) use ($intervention, $user_id, $file_name) {
|
||||||
|
|
||||||
// Store thumbnail to disk
|
dd($intervention->getWidth());
|
||||||
Storage::put("files/$user_id/{$size['name']}-{$file_name}", $intervention);
|
|
||||||
|
|
||||||
if ($is_last) {
|
if ($intervention->getWidth() > $size['size']) {
|
||||||
|
|
||||||
// Delete file after generate a thumbnail
|
// Generate thumbnail
|
||||||
Storage::disk('local')->delete("temp/$user_id/{$file_name}");
|
$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;
|
namespace Domain\Files\Actions;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Spatie\QueueableAction\QueueableAction;
|
|
||||||
use Intervention\Image\ImageManagerStatic as Image;
|
use Intervention\Image\ImageManagerStatic as Image;
|
||||||
use Domain\Files\Actions\CreateImageThumbnailAcionQueue;
|
use Domain\Files\Actions\CreateImageThumbnailAcionQueue;
|
||||||
|
|
||||||
|
|
||||||
class CreateImageThumbnailAction
|
class CreateImageThumbnailAction
|
||||||
{
|
{
|
||||||
use QueueableAction;
|
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
CreateImageThumbnailAcionQueue $action,
|
CreateImageThumbnailAcionQueue $action,
|
||||||
@@ -41,43 +39,11 @@ class CreateImageThumbnailAction
|
|||||||
// Make copy of file for the thumbnail generation
|
// Make copy of file for the thumbnail generation
|
||||||
Storage::disk('local')->copy("files/$user_id/{$file_name}", "temp/$user_id/{$file_name}");
|
Storage::disk('local')->copy("files/$user_id/{$file_name}", "temp/$user_id/{$file_name}");
|
||||||
|
|
||||||
// Create intervention image
|
// Create thumbnail instantly
|
||||||
$intervention = Image::make($file)->orientate();
|
$this->action->execute($file_name, $user_id, config('vuefilemanager.image_sizes.execute'));
|
||||||
|
|
||||||
// Generate avatar sizes
|
|
||||||
collect(config('vuefilemanager.image_sizes.execute') )
|
|
||||||
->each(function ($size) use ($intervention, $file_name, $user_id) {
|
|
||||||
|
|
||||||
// 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'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,10 @@ class DumpTrashController extends Controller
|
|||||||
// Delete thumbnail if exist
|
// Delete thumbnail if exist
|
||||||
if ($file->thumbnail) {
|
if ($file->thumbnail) {
|
||||||
|
|
||||||
collect(array_merge(config('vuefilemanager.image_sizes.queue'), config('vuefilemanager.image_sizes.execute')))
|
collect([
|
||||||
|
config('vuefilemanager.image_sizes.queue'),
|
||||||
|
config('vuefilemanager.image_sizes.execute'),
|
||||||
|
])->collapse()
|
||||||
->each(function ($size) use ($file) {
|
->each(function ($size) use ($file) {
|
||||||
|
|
||||||
Storage::delete("/files/$file->user_id/{$size['name']}-{$file->basename}");
|
Storage::delete("/files/$file->user_id/{$size['name']}-{$file->basename}");
|
||||||
|
|||||||
Reference in New Issue
Block a user