|
4 | 4 |
|
5 | 5 | use App\Models\User; |
6 | 6 | use Illuminate\Database\Eloquent\Factories\Factory; |
| 7 | +use Illuminate\Support\Facades\Storage; |
7 | 8 |
|
8 | 9 | /** |
9 | 10 | * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Showcase> |
@@ -106,4 +107,75 @@ public function both(): static |
106 | 107 | 'linux_download_url' => fake()->optional(0.5)->url(), |
107 | 108 | ]); |
108 | 109 | } |
| 110 | + |
| 111 | + public function withScreenshots(int $count = 3, bool $tall = false): static |
| 112 | + { |
| 113 | + return $this->state(function (array $attributes) use ($count, $tall) { |
| 114 | + $screenshots = []; |
| 115 | + |
| 116 | + for ($i = 0; $i < $count; $i++) { |
| 117 | + $screenshots[] = $this->generatePlaceholderScreenshot($tall); |
| 118 | + } |
| 119 | + |
| 120 | + return ['screenshots' => $screenshots]; |
| 121 | + }); |
| 122 | + } |
| 123 | + |
| 124 | + public function withTallScreenshots(int $count = 3): static |
| 125 | + { |
| 126 | + return $this->withScreenshots($count, tall: true); |
| 127 | + } |
| 128 | + |
| 129 | + public function withWideScreenshots(int $count = 3): static |
| 130 | + { |
| 131 | + return $this->withScreenshots($count, tall: false); |
| 132 | + } |
| 133 | + |
| 134 | + protected function generatePlaceholderScreenshot(bool $tall = false): string |
| 135 | + { |
| 136 | + $width = $tall ? 390 : 1280; |
| 137 | + $height = $tall ? 844 : 720; |
| 138 | + |
| 139 | + $image = imagecreatetruecolor($width, $height); |
| 140 | + |
| 141 | + $colors = [ |
| 142 | + [99, 102, 241], // Indigo |
| 143 | + [139, 92, 246], // Purple |
| 144 | + [236, 72, 153], // Pink |
| 145 | + [14, 165, 233], // Sky |
| 146 | + [34, 197, 94], // Green |
| 147 | + [249, 115, 22], // Orange |
| 148 | + ]; |
| 149 | + |
| 150 | + $color = fake()->randomElement($colors); |
| 151 | + $bgColor = imagecolorallocate($image, $color[0], $color[1], $color[2]); |
| 152 | + imagefill($image, 0, 0, $bgColor); |
| 153 | + |
| 154 | + $white = imagecolorallocate($image, 255, 255, 255); |
| 155 | + |
| 156 | + if ($tall) { |
| 157 | + // Draw phone UI elements |
| 158 | + imagefilledrectangle($image, 20, 60, $width - 20, 120, $white); |
| 159 | + imagefilledrectangle($image, 20, 140, $width - 20, 400, imagecolorallocatealpha($image, 255, 255, 255, 80)); |
| 160 | + imagefilledrectangle($image, 20, 420, ($width - 20) / 2 - 10, 600, imagecolorallocatealpha($image, 255, 255, 255, 80)); |
| 161 | + imagefilledrectangle($image, ($width - 20) / 2 + 10, 420, $width - 20, 600, imagecolorallocatealpha($image, 255, 255, 255, 80)); |
| 162 | + } else { |
| 163 | + // Draw desktop UI elements |
| 164 | + imagefilledrectangle($image, 0, 0, $width, 40, imagecolorallocatealpha($image, 0, 0, 0, 80)); |
| 165 | + imagefilledrectangle($image, 20, 60, 250, $height - 20, imagecolorallocatealpha($image, 255, 255, 255, 80)); |
| 166 | + imagefilledrectangle($image, 270, 60, $width - 20, $height - 20, imagecolorallocatealpha($image, 255, 255, 255, 90)); |
| 167 | + } |
| 168 | + |
| 169 | + $filename = 'showcase-screenshots/'.fake()->uuid().'.png'; |
| 170 | + Storage::disk('public')->makeDirectory('showcase-screenshots'); |
| 171 | + |
| 172 | + ob_start(); |
| 173 | + imagepng($image); |
| 174 | + $imageData = ob_get_clean(); |
| 175 | + imagedestroy($image); |
| 176 | + |
| 177 | + Storage::disk('public')->put($filename, $imageData); |
| 178 | + |
| 179 | + return $filename; |
| 180 | + } |
109 | 181 | } |
0 commit comments