Skip to content

Commit 865f633

Browse files
committed
Improve showcase galleries for mobile apps
1 parent 8c95fd1 commit 865f633

File tree

3 files changed

+87
-13
lines changed

3 files changed

+87
-13
lines changed

database/factories/ShowcaseFactory.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Models\User;
66
use Illuminate\Database\Eloquent\Factories\Factory;
7+
use Illuminate\Support\Facades\Storage;
78

89
/**
910
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Showcase>
@@ -106,4 +107,75 @@ public function both(): static
106107
'linux_download_url' => fake()->optional(0.5)->url(),
107108
]);
108109
}
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+
}
109181
}

database/seeders/ShowcaseSeeder.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,21 @@ class ShowcaseSeeder extends Seeder
1212
*/
1313
public function run(): void
1414
{
15-
// 10 approved showcases (mix of platforms)
16-
Showcase::factory(4)->approved()->mobile()->create();
17-
Showcase::factory(4)->approved()->desktop()->create();
18-
Showcase::factory(2)->approved()->both()->create();
15+
// Approved showcases with screenshots
16+
Showcase::factory(2)->approved()->mobile()->withTallScreenshots(3)->create();
17+
Showcase::factory(2)->approved()->mobile()->create();
18+
Showcase::factory(2)->approved()->desktop()->withWideScreenshots(3)->create();
19+
Showcase::factory(2)->approved()->desktop()->create();
20+
Showcase::factory(2)->approved()->both()->withTallScreenshots(2)->create();
1921

20-
// 5 recently approved (will show as "new")
21-
Showcase::factory(2)->recentlyApproved()->mobile()->create();
22-
Showcase::factory(2)->recentlyApproved()->desktop()->create();
23-
Showcase::factory(1)->recentlyApproved()->both()->create();
22+
// Recently approved (will show as "new") with screenshots
23+
Showcase::factory(2)->recentlyApproved()->mobile()->withTallScreenshots(4)->create();
24+
Showcase::factory(2)->recentlyApproved()->desktop()->withWideScreenshots(3)->create();
25+
Showcase::factory(1)->recentlyApproved()->both()->withWideScreenshots(2)->create();
2426

25-
// 5 pending review
26-
Showcase::factory(2)->pending()->mobile()->create();
27-
Showcase::factory(2)->pending()->desktop()->create();
27+
// Pending review
28+
Showcase::factory(2)->pending()->mobile()->withTallScreenshots(2)->create();
29+
Showcase::factory(2)->pending()->desktop()->withWideScreenshots(2)->create();
2830
Showcase::factory(1)->pending()->both()->create();
2931
}
3032
}

resources/views/components/showcase-card.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class="group relative overflow-hidden rounded-2xl border border-gray-200 bg-whit
4444
x-transition:enter-end="opacity-100"
4545
src="{{ Storage::disk('public')->url($screenshot) }}"
4646
alt="{{ $showcase->title }} screenshot {{ $index + 1 }}"
47-
class="absolute inset-0 w-full h-full object-cover"
47+
class="absolute inset-0 w-full h-full object-contain"
4848
>
4949
@endforeach
5050

@@ -90,7 +90,7 @@ class="w-2 h-2 rounded-full transition-colors"
9090
<img
9191
src="{{ Storage::disk('public')->url($showcase->image) }}"
9292
alt="{{ $showcase->title }}"
93-
class="w-full h-full object-cover"
93+
class="w-full h-full object-contain"
9494
>
9595
@else
9696
<div class="w-full h-full flex items-center justify-center">

0 commit comments

Comments
 (0)