dbXapp 2.0
RAD, CMS, Module und Runtime-IDE fuer dbXapp
Loading...
Searching...
No Matches
generate_dbxapp_merch_mockups.php
Go to the documentation of this file.
1<?php
2declare(strict_types=1);
3
4$root = dirname(__DIR__, 4);
5$logoFile = $root . '/dbXapp-Logo.jpeg';
6$outDir = $root . '/files/shop/img';
7require_once $root . '/dbx/include/dbxApi.php';
8
9if (!extension_loaded('gd')) {
10 fwrite(STDERR, "GD extension is required.\n");
11 exit(1);
12}
13if (!is_file($logoFile)) {
14 fwrite(STDERR, "Logo not found: $logoFile\n");
15 exit(1);
16}
17if (!is_dir($outDir)) {
18 mkdir($outDir, 0775, true);
19}
20
21$logo = imagecreatefromjpeg($logoFile);
22if (!$logo) {
23 fwrite(STDERR, "Could not read logo.\n");
24 exit(1);
25}
26
27function c($img, int $r, int $g, int $b, int $a = 0): int {
28 return imagecolorallocatealpha($img, $r, $g, $b, $a);
29}
30
31function roundedRect($img, int $x, int $y, int $w, int $h, int $r, int $color): void {
32 imagefilledrectangle($img, $x + $r, $y, $x + $w - $r, $y + $h, $color);
33 imagefilledrectangle($img, $x, $y + $r, $x + $w, $y + $h - $r, $color);
34 imagefilledellipse($img, $x + $r, $y + $r, $r * 2, $r * 2, $color);
35 imagefilledellipse($img, $x + $w - $r, $y + $r, $r * 2, $r * 2, $color);
36 imagefilledellipse($img, $x + $r, $y + $h - $r, $r * 2, $r * 2, $color);
37 imagefilledellipse($img, $x + $w - $r, $y + $h - $r, $r * 2, $r * 2, $color);
38}
39
40function gradientBackground($img): void {
41 $w = imagesx($img);
42 $h = imagesy($img);
43 for ($y = 0; $y < $h; $y++) {
44 $t = $y / max(1, $h - 1);
45 $r = (int)(244 - 18 * $t);
46 $g = (int)(249 - 28 * $t);
47 $b = (int)(255 - 22 * $t);
48 imageline($img, 0, $y, $w, $y, c($img, $r, $g, $b));
49 }
50 imagefilledellipse($img, 260, 120, 520, 220, c($img, 221, 238, 255, 30));
51 imagefilledellipse($img, 1060, 150, 360, 180, c($img, 214, 232, 255, 45));
52 imagefilledellipse($img, 640, 710, 780, 96, c($img, 24, 50, 93, 94));
53}
54
55function addLogo($img, $logo, int $x, int $y, int $w, int $h): void {
56 $lw = imagesx($logo);
57 $lh = imagesy($logo);
58 imagecopyresampled($img, $logo, $x, $y, 0, 0, $w, $h, $lw, $lh);
59}
60
61function addTitle($img, string $title, string $subtitle = ''): void {
62 $dark = c($img, 27, 44, 68);
63 $muted = c($img, 92, 111, 136);
64 imagestring($img, 5, 46, 42, $title, $dark);
65 if ($subtitle !== '') {
66 imagestring($img, 3, 46, 66, $subtitle, $muted);
67 }
68}
69
70function drawShine($img, int $x, int $y, int $w, int $h): void {
71 imagefilledellipse($img, $x + (int)($w * .28), $y + (int)($h * .18), (int)($w * .42), (int)($h * .12), c($img, 255, 255, 255, 68));
72 imagefilledrectangle($img, $x + (int)($w * .12), $y + 16, $x + (int)($w * .18), $y + $h - 16, c($img, 255, 255, 255, 95));
73}
74
75function drawMug($img, $logo, string $bodyColor): void {
76 $dark = $bodyColor === 'blue' ? c($img, 18, 51, 112) : c($img, 246, 250, 255);
77 $side = $bodyColor === 'blue' ? c($img, 11, 35, 82) : c($img, 224, 235, 248);
78 $rim = c($img, 255, 255, 255, 35);
79 imagefilledellipse($img, 641, 270, 394, 72, c($img, 25, 45, 78, 72));
80 imagefilledrectangle($img, 444, 270, 838, 560, $dark);
81 imagefilledellipse($img, 641, 560, 394, 72, $side);
82 imagefilledellipse($img, 641, 270, 394, 72, $rim);
83 imageellipse($img, 641, 270, 394, 72, c($img, 110, 150, 205, 20));
84 imagefilledellipse($img, 865, 405, 146, 190, c($img, 210, 225, 245, 20));
85 imagefilledellipse($img, 856, 405, 92, 132, c($img, 238, 246, 255));
86 drawShine($img, 444, 270, 394, 290);
87 addLogo($img, $logo, 525, 325, 230, 188);
88}
89
90function drawShirt($img, $logo, string $kind): void {
91 $base = $kind === 'hoodie' ? c($img, 24, 39, 64) : c($img, 16, 26, 44);
92 $shade = c($img, 7, 18, 35);
93 if ($kind === 'cap') {
94 imagefilledellipse($img, 640, 385, 380, 190, $base);
95 imagefilledellipse($img, 770, 480, 350, 90, c($img, 12, 32, 70));
96 imagearc($img, 640, 385, 348, 164, 190, 350, c($img, 120, 160, 220));
97 addLogo($img, $logo, 555, 344, 158, 128);
98 return;
99 }
100 if ($kind === 'hoodie') {
101 imagefilledellipse($img, 640, 264, 240, 190, $shade);
102 imagefilledellipse($img, 640, 290, 172, 126, c($img, 230, 238, 250));
103 }
104 imagefilledpolygon($img, array(405,270, 530,220, 600,290, 680,290, 750,220, 875,270, 810,435, 760,412, 760,620, 520,620, 520,412, 470,435), 12, $base);
105 imagefilledpolygon($img, array(405,270, 530,220, 520,412, 470,435), 4, $shade);
106 imagefilledpolygon($img, array(750,220, 875,270, 810,435, 760,412), 4, $shade);
107 if ($kind === 'hoodie') {
108 roundedRect($img, 570, 505, 140, 62, 16, c($img, 13, 28, 52));
109 imageline($img, 615, 300, 585, 440, c($img, 210, 220, 235));
110 imageline($img, 665, 300, 695, 440, c($img, 210, 220, 235));
111 }
112 addLogo($img, $logo, 548, 342, 184, 150);
113}
114
115function drawFlatProduct($img, $logo, string $type): void {
116 if ($type === 'poster') {
117 roundedRect($img, 430, 150, 420, 520, 10, c($img, 255, 255, 255));
118 imagerectangle($img, 430, 150, 850, 670, c($img, 194, 211, 232));
119 addLogo($img, $logo, 475, 225, 330, 270);
120 return;
121 }
122 if ($type === 'notebook') {
123 roundedRect($img, 448, 180, 384, 500, 22, c($img, 19, 42, 86));
124 roundedRect($img, 486, 230, 310, 390, 14, c($img, 240, 247, 255));
125 addLogo($img, $logo, 522, 325, 238, 194);
126 for ($i = 0; $i < 8; $i++) imagefilledellipse($img, 466, 235 + $i * 48, 14, 14, c($img, 210, 225, 244));
127 return;
128 }
129 $w = $type === 'deskmat' ? 690 : 520;
130 $h = $type === 'deskmat' ? 340 : 310;
131 $x = 640 - (int)($w / 2);
132 $y = 400 - (int)($h / 2);
133 roundedRect($img, $x, $y, $w, $h, 28, c($img, 15, 34, 73));
134 roundedRect($img, $x + 18, $y + 18, $w - 36, $h - 36, 20, c($img, 22, 55, 126));
135 addLogo($img, $logo, $x + (int)($w * .29), $y + (int)($h * .22), (int)($w * .42), (int)($h * .55));
136}
137
138function drawAccessory($img, $logo, string $type): void {
139 switch ($type) {
140 case 'bottle':
141 case 'thermo':
142 roundedRect($img, 555, 185, 170, 475, 52, c($img, 230, 238, 248));
143 roundedRect($img, 580, 125, 120, 82, 24, c($img, 28, 50, 82));
144 imagefilledrectangle($img, 590, 110, 690, 140, c($img, 18, 34, 58));
145 drawShine($img, 555, 185, 170, 475);
146 addLogo($img, $logo, 585, 330, 110, 90);
147 break;
148 case 'usb':
149 roundedRect($img, 420, 330, 340, 110, 24, c($img, 25, 47, 82));
150 roundedRect($img, 745, 350, 120, 70, 10, c($img, 198, 211, 226));
151 addLogo($img, $logo, 486, 345, 160, 72);
152 break;
153 case 'powerbank':
154 roundedRect($img, 430, 235, 420, 290, 34, c($img, 20, 42, 78));
155 roundedRect($img, 456, 260, 368, 238, 24, c($img, 30, 72, 144));
156 addLogo($img, $logo, 535, 320, 210, 172);
157 imagefilledrectangle($img, 797, 315, 820, 360, c($img, 200, 218, 238));
158 break;
159 case 'bag':
160 roundedRect($img, 455, 270, 370, 330, 16, c($img, 238, 241, 245));
161 imagearc($img, 640, 278, 220, 170, 190, 350, c($img, 45, 62, 90));
162 addLogo($img, $logo, 535, 380, 210, 172);
163 break;
164 case 'lanyard':
165 imagesetthickness($img, 34);
166 imagearc($img, 640, 310, 420, 300, 20, 340, c($img, 17, 63, 145));
167 imagesetthickness($img, 1);
168 roundedRect($img, 570, 470, 140, 95, 12, c($img, 245, 249, 255));
169 addLogo($img, $logo, 590, 485, 100, 62);
170 break;
171 case 'keychain':
172 imagefilledellipse($img, 620, 260, 150, 150, c($img, 204, 216, 232));
173 imagefilledellipse($img, 620, 260, 92, 92, c($img, 238, 246, 255));
174 roundedRect($img, 535, 350, 210, 150, 26, c($img, 20, 50, 105));
175 addLogo($img, $logo, 575, 380, 130, 92);
176 break;
177 case 'phone':
178 roundedRect($img, 530, 155, 220, 500, 34, c($img, 18, 31, 52));
179 roundedRect($img, 548, 185, 184, 440, 24, c($img, 236, 243, 252));
180 addLogo($img, $logo, 570, 335, 140, 114);
181 break;
182 case 'sleeve':
183 roundedRect($img, 430, 235, 420, 300, 28, c($img, 28, 49, 78));
184 imageline($img, 450, 295, 830, 295, c($img, 82, 112, 150));
185 addLogo($img, $logo, 535, 335, 210, 172);
186 break;
187 case 'socks':
188 roundedRect($img, 500, 170, 110, 390, 34, c($img, 24, 42, 68));
189 roundedRect($img, 590, 390, 210, 120, 36, c($img, 24, 42, 68));
190 roundedRect($img, 650, 170, 110, 390, 34, c($img, 238, 242, 248));
191 roundedRect($img, 740, 390, 210, 120, 36, c($img, 238, 242, 248));
192 addLogo($img, $logo, 525, 270, 70, 58);
193 addLogo($img, $logo, 675, 270, 70, 58);
194 break;
195 case 'beanie':
196 imagefilledellipse($img, 640, 420, 410, 290, c($img, 22, 39, 68));
197 imagefilledrectangle($img, 440, 420, 840, 540, c($img, 19, 34, 61));
198 roundedRect($img, 560, 425, 160, 86, 14, c($img, 241, 246, 252));
199 addLogo($img, $logo, 580, 440, 120, 56);
200 break;
201 case 'sticker':
202 for ($i = 0; $i < 5; $i++) {
203 $x = 420 + $i * 92;
204 imagefilledellipse($img, $x, 390 + (($i % 2) * 38), 130, 130, c($img, 255, 255, 255));
205 addLogo($img, $logo, $x - 44, 350 + (($i % 2) * 38), 88, 72);
206 }
207 break;
208 case 'pen':
209 for ($i = 0; $i < 3; $i++) {
210 $y = 310 + $i * 70;
211 roundedRect($img, 390, $y, 500, 34, 17, $i === 1 ? c($img, 225, 36, 48) : c($img, 20, 55, 125));
212 imagefilledpolygon($img, array(890,$y, 950,$y+17, 890,$y+34), 3, c($img, 170, 185, 205));
213 addLogo($img, $logo, 520, $y - 12, 92, 50);
214 }
215 break;
216 }
217}
218
219function createMockup($logo, string $type, string $title, string $file): void {
220 $img = imagecreatetruecolor(1280, 800);
221 imagealphablending($img, true);
222 imagesavealpha($img, true);
223 gradientBackground($img);
224 addTitle($img, $title, 'dbXapp Merchandise');
225
226 switch ($type) {
227 case 'mug-blue': drawMug($img, $logo, 'blue'); break;
228 case 'mug-white': drawMug($img, $logo, 'white'); break;
229 case 'shirt': drawShirt($img, $logo, 'shirt'); break;
230 case 'hoodie': drawShirt($img, $logo, 'hoodie'); break;
231 case 'cap': drawShirt($img, $logo, 'cap'); break;
232 case 'mousepad': drawFlatProduct($img, $logo, 'mousepad'); break;
233 case 'deskmat': drawFlatProduct($img, $logo, 'deskmat'); break;
234 case 'poster': drawFlatProduct($img, $logo, 'poster'); break;
235 default: drawAccessory($img, $logo, $type); break;
236 }
237
238 imagewebp($img, $file, 88);
239 imagedestroy($img);
240}
241
242$specs = array(
243 'DBX-SHIRT' => array('shirt', 'T-Shirt mit dbXapp Logo', 'mockup-dbxapp-t-shirt.webp'),
244 'DBX-CAP' => array('cap', 'Kappe mit dbXapp Logo', 'mockup-dbxapp-kappe.webp'),
245 'DBX-HOODIE' => array('hoodie', 'Hoodie mit dbXapp Logo', 'mockup-dbxapp-hoodie.webp'),
246 'DBX-MUG-BLUE' => array('mug-blue', 'dbXapp Kaffeetasse Blau', 'mockup-dbxapp-kaffeetasse-blau.webp'),
247 'DBX-MUG-WHITE' => array('mug-white', 'dbXapp Kaffeetasse Weiss', 'mockup-dbxapp-kaffeetasse-weiss.webp'),
248 'DBX-MOUSEPAD' => array('mousepad', 'dbXapp Mauspad Classic', 'mockup-dbxapp-mauspad-classic.webp'),
249 'DBX-MOUSEPAD-XL' => array('mousepad', 'dbXapp Mauspad XL', 'mockup-dbxapp-mauspad-xl.webp'),
250 'DBX-DESKMAT' => array('deskmat', 'dbXapp Deskmat', 'mockup-dbxapp-deskmat.webp'),
251 'DBX-STICKER-SET' => array('sticker', 'dbXapp Sticker Set', 'mockup-dbxapp-sticker-set.webp'),
252 'DBX-NOTEBOOK' => array('notebook', 'dbXapp Notizbuch', 'mockup-dbxapp-notizbuch.webp'),
253 'DBX-PEN-SET' => array('pen', 'dbXapp Kugelschreiber Set', 'mockup-dbxapp-kugelschreiber-set.webp'),
254 'DBX-LANYARD' => array('lanyard', 'dbXapp Lanyard', 'mockup-dbxapp-lanyard.webp'),
255 'DBX-TOTE-BAG' => array('bag', 'dbXapp Stofftasche', 'mockup-dbxapp-stofftasche.webp'),
256 'DBX-BOTTLE' => array('bottle', 'dbXapp Trinkflasche', 'mockup-dbxapp-trinkflasche.webp'),
257 'DBX-THERMO-MUG' => array('thermo', 'dbXapp Thermobecher', 'mockup-dbxapp-thermobecher.webp'),
258 'DBX-USB-STICK' => array('usb', 'dbXapp USB-Stick', 'mockup-dbxapp-usb-stick.webp'),
259 'DBX-POWERBANK' => array('powerbank', 'dbXapp Powerbank', 'mockup-dbxapp-powerbank.webp'),
260 'DBX-KEYCHAIN' => array('keychain', 'dbXapp Schluesselanhaenger', 'mockup-dbxapp-schluesselanhaenger.webp'),
261 'DBX-POSTER' => array('poster', 'dbXapp Poster', 'mockup-dbxapp-poster.webp'),
262 'DBX-SOCKS' => array('socks', 'dbXapp Socken', 'mockup-dbxapp-socken.webp'),
263 'DBX-BEANIE' => array('beanie', 'dbXapp Beanie', 'mockup-dbxapp-beanie.webp'),
264 'DBX-PHONE-CASE' => array('phone', 'dbXapp Smartphone-Huelle', 'mockup-dbxapp-smartphone-huelle.webp'),
265 'DBX-LAPTOP-SLEEVE' => array('sleeve', 'dbXapp Laptop Sleeve', 'mockup-dbxapp-laptop-sleeve.webp'),
266);
267
268$repo = dbx()->get_include_obj('dbxShopRepository', 'dbxShop');
269$repo->install();
271foreach ($specs as $sku => $spec) {
272 [$type, $fallbackTitle, $fileName] = $spec;
273 $product = $repo->productBySku($sku, false);
274 if (!$product) {
275 continue;
276 }
277 $title = trim((string)($product['title'] ?? '')) ?: $fallbackTitle;
278 $path = $outDir . '/' . $fileName;
279 createMockup($logo, $type, $title, $path);
280 $webPath = 'files/shop/img/' . $fileName;
281 $repo->saveImage((int)$product['id'], 0, $webPath, $title, $title . ' Produktbild', 1, 5);
282 $count++;
283}
284
285imagedestroy($logo);
286echo "Generated $count dbXapp merch mockups.\n";
drawFlatProduct($img, $logo, string $type)
if(! $logo) c($img, int $r, int $g, int $b, int $a=0)
if(!extension_loaded('gd')) if(!is_file( $logoFile)) if(!is_dir($outDir)) $logo
drawAccessory($img, $logo, string $type)
drawMug($img, $logo, string $bodyColor)
addLogo($img, $logo, int $x, int $y, int $w, int $h)
drawShirt($img, $logo, string $kind)
drawShine($img, int $x, int $y, int $w, int $h)
addTitle($img, string $title, string $subtitle='')
createMockup($logo, string $type, string $title, string $file)
roundedRect($img, int $x, int $y, int $w, int $h, int $r, int $color)
exit
Definition index.php:532
if( $syncRequest)
Definition index.php:520
DBX schema administration.