Generate thumbnails for demo data

This commit is contained in:
Čarodej
2021-11-03 17:10:23 +01:00
parent f139dbae08
commit 6203581893
30 changed files with 96 additions and 80 deletions

View File

@@ -623,105 +623,92 @@ class SetupDevEnvironment extends Command
// Get meme gallery // Get meme gallery
collect([ collect([
'Eggcited bro.jpg', 'demo/images/memes/Eggcited bro.jpg',
'Get a Rest.jpg', 'demo/images/memes/Get a Rest.jpg',
'Get Your Shit Together.jpg', 'demo/images/memes/Get Your Shit Together.jpg',
'Happiness is when you are right beside me.jpg', 'demo/images/memes/Happiness is when you are right beside me.jpg',
'Have a Nice Day.jpg', 'demo/images/memes/Have a Nice Day.jpg',
'It Works On My Machine.jpg', 'demo/images/memes/It Works On My Machine.jpg',
'I am Just Trying to shine.jpg', 'demo/images/memes/I am Just Trying to shine.jpg',
'It Works On My Machine.jpg', 'demo/images/memes/Missing you It is Pig Time.jpg',
'Missing you It is Pig Time.jpg', 'demo/images/memes/Sofishticated.jpg',
'Sofishticated.jpg', 'demo/images/memes/whaaaaat.jpg',
'whaaaaat.jpg', 'demo/images/memes/You Are My Sunshine.jpg',
'You Are My Sunshine.jpg',
]) ])
->each(function ($file) use ($user) { ->each(function ($file) use ($user) {
$basename = Str::random(12) . '-' . $file;
// Copy file into app storage $thumbnail = $this->generate_thumbnails($file, $user);
Storage::putFileAs("files/$user->id", storage_path("demo/images/memes/$file"), $basename, 'private');
Storage::putFileAs("files/$user->id", storage_path("demo/images/memes/thumbnail-$file"), "thumbnail-$basename", 'private');
// Create file record // Create file record
File::create([ File::create([
'parent_id' => null, 'parent_id' => null,
'user_id' => $user->id, 'user_id' => $user->id,
'name' => $file, 'name' => $thumbnail['name'],
'basename' => $basename, 'basename' => $thumbnail['basename'],
'type' => 'image', 'type' => 'image',
'author' => 'user', 'author' => 'user',
'mimetype' => 'jpg', 'mimetype' => 'jpg',
'filesize' => rand(1000000, 4000000), 'filesize' => rand(1000000, 4000000),
'thumbnail' => "thumbnail-$basename",
'created_at' => now()->subMinutes(rand(1, 5)), 'created_at' => now()->subMinutes(rand(1, 5)),
]); ]);
}); });
// Get apartments gallery // Get apartments gallery
collect([ collect([
'Apartment Architecture Ceiling Chairs.jpg', 'demo/images/apartments/Apartment Architecture Ceiling Chairs.jpg',
'Apartment Chair.jpg', 'demo/images/apartments/Apartment Chair.jpg',
'Apartment Contemporary Couch Curtains.jpg', 'demo/images/apartments/Apartment Contemporary Couch Curtains.jpg',
'Brown Wooden Center Table.jpg', 'demo/images/apartments/Brown Wooden Center Table.jpg',
'Home.jpg', 'demo/images/apartments/Home.jpg',
'Kitchen Appliances.jpg', 'demo/images/apartments/Kitchen Appliances.jpg',
'Kitchen Island.jpg', 'demo/images/apartments/Kitchen Island.jpg',
]) ])
->each(function ($file) use ($user, $apartments) { ->each(function ($file) use ($user, $apartments) {
$basename = Str::random(12) . '-' . $file;
// Copy file into app storage $thumbnail = $this->generate_thumbnails($file, $user);
Storage::putFileAs("files/$user->id", storage_path("demo/images/apartments/$file"), $basename, 'private');
Storage::putFileAs("files/$user->id", storage_path("demo/images/apartments/thumbnail-$file"), "thumbnail-$basename", 'private');
// Create file record // Create file record
File::create([ File::create([
'parent_id' => $apartments->id, 'parent_id' => $apartments->id,
'user_id' => $user->id, 'user_id' => $user->id,
'name' => $file, 'name' => $thumbnail['name'],
'basename' => $basename, 'basename' => $thumbnail['basename'],
'type' => 'image', 'type' => 'image',
'author' => 'user', 'author' => 'user',
'mimetype' => 'jpg', 'mimetype' => 'jpg',
'filesize' => rand(1000000, 4000000), 'filesize' => rand(1000000, 4000000),
'thumbnail' => "thumbnail-$basename",
'created_at' => now()->subMinutes(rand(1, 5)), 'created_at' => now()->subMinutes(rand(1, 5)),
]); ]);
}); });
// Get nature gallery // Get nature gallery
collect([ collect([
'Bird Patterncolorful Green.jpg', 'demo/images/nature/Bird Patterncolorful Green.jpg',
'Close Up Of Peacock.jpg', 'demo/images/nature/Close Up Of Peacock.jpg',
'Close Up Photography Of Tiger.jpg', 'demo/images/nature/Close Up Photography Of Tiger.jpg',
'Cold Nature Cute Ice.jpg', 'demo/images/nature/Cold Nature Cute Ice.jpg',
'Landscape Photo of Forest.jpg', 'demo/images/nature/Landscape Photo of Forest.jpg',
'Photo of Hawksbill Sea Turtle.jpg', 'demo/images/nature/Photo of Hawksbill Sea Turtle.jpg',
'Photo Of Reindeer in The Snow.jpg', 'demo/images/nature/Photo Of Reindeer in The Snow.jpg',
'View Of Elephant in Water.jpg', 'demo/images/nature/View Of Elephant in Water.jpg',
'Waterfall Between Trees.jpg', 'demo/images/nature/Waterfall Between Trees.jpg',
'Wildlife Photography of Elephant During Golden Hour.jpg', 'demo/images/nature/Wildlife Photography of Elephant During Golden Hour.jpg',
'Yellow Animal Eyes Fur.jpg', 'demo/images/nature/Yellow Animal Eyes Fur.jpg',
]) ])
->each(function ($file) use ($user, $nature) { ->each(function ($file) use ($user, $nature) {
$basename = Str::random(12) . '-' . $file;
// Copy file into app storage $thumbnail = $this->generate_thumbnails($file, $user);
Storage::putFileAs("files/$user->id", storage_path("demo/images/nature/$file"), $basename, 'private');
Storage::putFileAs("files/$user->id", storage_path("demo/images/nature/thumbnail-$file"), "thumbnail-$basename", 'private');
// Create file record // Create file record
File::create([ File::create([
'parent_id' => $nature->id, 'parent_id' => $nature->id,
'user_id' => $user->id, 'user_id' => $user->id,
'name' => $file, 'name' => $thumbnail['name'],
'basename' => $basename, 'basename' => $thumbnail['basename'],
'type' => 'image', 'type' => 'image',
'author' => 'user', 'author' => 'user',
'mimetype' => 'jpg', 'mimetype' => 'jpg',
'filesize' => rand(1000000, 4000000), 'filesize' => rand(1000000, 4000000),
'thumbnail' => "thumbnail-$basename",
'created_at' => now()->subMinutes(rand(1, 5)), 'created_at' => now()->subMinutes(rand(1, 5)),
]); ]);
}); });
@@ -851,80 +838,65 @@ class SetupDevEnvironment extends Command
// Get meme gallery // Get meme gallery
collect([ collect([
'Sofishticated.jpg', 'demo/images/memes/Sofishticated.jpg',
'whaaaaat.jpg', 'demo/images/memes/whaaaaat.jpg',
]) ])
->each(function ($file) use ($owner, $folder) { ->each(function ($file) use ($owner, $folder) {
$basename = Str::random(12) . '-' . $file; $thumbnail = $this->generate_thumbnails($file, $owner);
// Copy file into app storage
Storage::putFileAs("files/$owner->id", storage_path("demo/images/memes/$file"), $basename, 'private');
Storage::putFileAs("files/$owner->id", storage_path("demo/images/memes/thumbnail-$file"), "thumbnail-$basename", 'private');
// Create file record // Create file record
File::create([ File::create([
'parent_id' => $folder->id, 'parent_id' => $folder->id,
'user_id' => $owner->id, 'user_id' => $owner->id,
'name' => $file, 'name' => $thumbnail['name'],
'basename' => $basename, 'basename' => $thumbnail['basename'],
'type' => 'image', 'type' => 'image',
'author' => 'user', 'author' => 'user',
'mimetype' => 'jpg', 'mimetype' => 'jpg',
'filesize' => rand(1000000, 4000000), 'filesize' => rand(1000000, 4000000),
'thumbnail' => "thumbnail-$basename",
'created_at' => now()->subMinutes(rand(1, 5)), 'created_at' => now()->subMinutes(rand(1, 5)),
]); ]);
}); });
// Get meme gallery // Get meme gallery
collect([ collect([
'You Are My Sunshine.jpg', 'demo/images/memes/You Are My Sunshine.jpg',
]) ])
->each(function ($file) use ($johan, $folder) { ->each(function ($file) use ($johan, $folder) {
$basename = Str::random(12) . '-' . $file; $thumbnail = $this->generate_thumbnails($file, $johan);
// Copy file into app storage
Storage::putFileAs("files/$johan->id", storage_path("demo/images/memes/$file"), $basename, 'private');
Storage::putFileAs("files/$johan->id", storage_path("demo/images/memes/thumbnail-$file"), "thumbnail-$basename", 'private');
// Create file record // Create file record
File::create([ File::create([
'parent_id' => $folder->id, 'parent_id' => $folder->id,
'user_id' => $johan->id, 'user_id' => $johan->id,
'name' => $file, 'name' => $thumbnail['name'],
'basename' => $basename, 'basename' => $thumbnail['basename'],
'type' => 'image', 'type' => 'image',
'author' => 'user', 'author' => 'user',
'mimetype' => 'jpg', 'mimetype' => 'jpg',
'filesize' => rand(1000000, 4000000), 'filesize' => rand(1000000, 4000000),
'thumbnail' => "thumbnail-$basename",
'created_at' => now()->subMinutes(rand(1, 5)), 'created_at' => now()->subMinutes(rand(1, 5)),
]); ]);
}); });
collect([ collect([
'Eggcited bro.jpg', 'demo/images/memes/Eggcited bro.jpg',
'Get a Rest.jpg', 'demo/images/memes/Get a Rest.jpg',
]) ])
->each(function ($file) use ($member, $hug) { ->each(function ($file) use ($member, $hug) {
$basename = Str::random(12) . '-' . $file; $thumbnail = $this->generate_thumbnails($file, $member);
// Copy file into app storage
Storage::putFileAs("files/$member->id", storage_path("demo/images/memes/$file"), $basename, 'private');
Storage::putFileAs("files/$member->id", storage_path("demo/images/memes/thumbnail-$file"), "thumbnail-$basename", 'private');
// Create file record // Create file record
File::create([ File::create([
'parent_id' => $hug->id, 'parent_id' => $hug->id,
'user_id' => $member->id, 'user_id' => $member->id,
'name' => $file, 'name' => $thumbnail['name'],
'basename' => $basename, 'basename' => $thumbnail['basename'],
'type' => 'image', 'type' => 'image',
'author' => 'user', 'author' => 'user',
'mimetype' => 'jpg', 'mimetype' => 'jpg',
'filesize' => rand(1000000, 4000000), 'filesize' => rand(1000000, 4000000),
'thumbnail' => "thumbnail-$basename",
'created_at' => now()->subMinutes(rand(1, 5)), 'created_at' => now()->subMinutes(rand(1, 5)),
]); ]);
}); });
@@ -1136,6 +1108,8 @@ class SetupDevEnvironment extends Command
// Create intervention image // Create intervention image
$img = Image::make($image); $img = Image::make($image);
$this->info("Generating thumbnails for $avatar...");
// Generate avatar // Generate avatar
collect(config('vuefilemanager.avatar_sizes')) collect(config('vuefilemanager.avatar_sizes'))
->each(function ($size) use ($img, $image, $avatar_name) { ->each(function ($size) use ($img, $image, $avatar_name) {
@@ -1149,4 +1123,46 @@ class SetupDevEnvironment extends Command
return $avatar_name; return $avatar_name;
} }
/**
* @param $file
* @param $user
* @return string
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
private function generate_thumbnails($file, $user): array
{
$image = \Illuminate\Support\Facades\File::get(storage_path($file));
// Create avatar name
$file_name = Str::uuid() . '.jpg';
// Create intervention image
$intervention = Image::make($image)->orientate();
$this->info("Generating thumbnails for $file...");
// Generate avatar sizes
collect(config('vuefilemanager.image_sizes'))
->each(function ($size) use ($intervention, $file_name, $user) {
// Create thumbnail only if image is larger than predefined image sizes
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);
}
});
// Store original to disk
Storage::put("files/$user->id/{$file_name}", $intervention);
return [
'basename' => $file_name,
'name' => head(explode('.', last(explode('/', $file)))),
];
}
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 57 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 95 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 227 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 98 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 149 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 238 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 237 KiB