diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 15b3393e..29703b1d 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -91,7 +91,7 @@ class UserFactory extends Factory public function withProfilePicture(): static { - $profilePhoto = $this->faker->image(null, 500, 500); + $profilePhoto = $this->generateProfilePhoto(); /** @see FileHelpers::hashName */ $path = 'profile-photos/'.Str::random(40).'.png'; Storage::disk(config('filesystems.public'))->put($path, $profilePhoto); @@ -103,6 +103,21 @@ class UserFactory extends Factory }); } + /** + * Generates a PNG image with a random background color. + * Note: The image is generated locally, since downloading a placeholder image (Faker image()) depends on an external service. + */ + private function generateProfilePhoto(): string + { + $image = imagecreatetruecolor(500, 500); + $color = imagecolorallocate($image, $this->faker->numberBetween(0, 255), $this->faker->numberBetween(0, 255), $this->faker->numberBetween(0, 255)); + imagefill($image, 0, 0, $color); + ob_start(); + imagepng($image); + + return (string) ob_get_clean(); + } + /** * Indicate that the user should have a personal team. */