Skip to content

Commit

Permalink
cs
Browse files Browse the repository at this point in the history
  • Loading branch information
danharrin committed Feb 7, 2024
1 parent 985ed79 commit ab7f4ec
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions app/Console/Commands/GetRandomImages.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,16 @@ protected function getRandomImages($schema)
$progressBar->start();

foreach (range(1, $amount) as $i) {

$url = "https://source.unsplash.com/{$size}/?img=1," . implode(',', $terms);
$image = file_get_contents($url);

File::ensureDirectoryExists(database_path('seeders/local_images/' . $size));
$filename = Str::uuid() . '.jpg';

File::put(database_path(
path: "seeders/local_images/{$size}/{$filename}"),
File::put(
database_path(
path: "seeders/local_images/{$size}/{$filename}"
),
contents: $image
);

Expand All @@ -83,7 +84,7 @@ protected function removeDuplicates($schema)
{
['size' => $size] = $schema;

$allFiles = fn() => collect(File::files(database_path('seeders/local_images/' . $size)));
$allFiles = fn () => collect(File::files(database_path('seeders/local_images/' . $size)));

$uniqueImageSet = $allFiles()
->mapWithKeys(fn ($file) => [md5_file($file->getPathname()) => $file->getPathname()])
Expand All @@ -94,6 +95,6 @@ protected function removeDuplicates($schema)
->diff($uniqueImageSet)
->each(fn ($file) => File::delete($file));

$this->info("Kept " . $uniqueImageSet->count() . " unique files from size $size");
$this->info('Kept ' . $uniqueImageSet->count() . " unique files from size $size");
}
}
1 change: 0 additions & 1 deletion database/factories/Shop/ProductFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Database\Factories\Shop;

use App\Models\Shop\Product;
use Database\Seeders\DatabaseSeeder;
use Database\Seeders\LocalImages;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
Expand Down
1 change: 1 addition & 0 deletions database/seeders/LocalImages.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
class LocalImages
{
public const SIZE_200x200 = '200x200';

public const SIZE_1280x720 = '1280x720';

public static function getRandomFile(?string $size = LocalImages::SIZE_200x200): SplFileInfo
Expand Down

0 comments on commit ab7f4ec

Please sign in to comment.