- Ordnerstruktur mit public/-Docroot, Deny-.htaccess für app/bin/config/data/storage - CLAUDE.md mit Leitplanken (self-hosted only, Single Source of Truth, Component-first) - Design-Tokens aus alter Seite extrahiert (Akzent #e20612, Coolvetica/Abel als woff2) - Front Controller mit Routen-Register, Sitemap, Canonical, JSON-LD (SportsClub) - Startseite: Hero, Instagram-Feed (lokaler Cache), Historie/Sportheim, Stats, Partner, Kontakt - Kontaktformular via PHPMailer/Brevo mit Honeypot + HMAC-Time-Trap (kein reCAPTCHA) - bin/instagram-sync.php: Scraper mit Strategie-Kette, flock, atomarem Cache, lokalen Bildern Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
77 lines
2.1 KiB
PHP
77 lines
2.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* Responsive Bild-Varianten erzeugen (GD, läuft auch auf Shared Hosting).
|
|
*
|
|
* Resize (proportional auf Zielbreiten):
|
|
* php bin/img-resize.php <quelle> <ziel-basis> <breite>[,<breite>...] [qualität=78]
|
|
* → ziel-basis-<breite>.jpg je Breite
|
|
*
|
|
* Crop (exaktes Format, mittig beschnitten, z.B. OG-Image):
|
|
* php bin/img-resize.php --crop <quelle> <ziel.jpg> <breite>x<höhe> [qualität=78]
|
|
*/
|
|
if (PHP_SAPI !== 'cli') {
|
|
exit(1);
|
|
}
|
|
|
|
$args = array_slice($argv, 1);
|
|
$crop = false;
|
|
if (($args[0] ?? '') === '--crop') {
|
|
$crop = true;
|
|
array_shift($args);
|
|
}
|
|
|
|
if (count($args) < 3) {
|
|
fwrite(STDERR, "Nutzung: siehe Datei-Kommentar\n");
|
|
exit(1);
|
|
}
|
|
|
|
[$src, $dest, $spec] = $args;
|
|
$quality = (int) ($args[3] ?? 78);
|
|
|
|
$image = match (strtolower(pathinfo($src, PATHINFO_EXTENSION))) {
|
|
'jpg', 'jpeg' => imagecreatefromjpeg($src),
|
|
'png' => imagecreatefrompng($src),
|
|
'webp' => imagecreatefromwebp($src),
|
|
default => null,
|
|
};
|
|
if (!$image) {
|
|
fwrite(STDERR, "Kann Quelle nicht lesen: {$src}\n");
|
|
exit(1);
|
|
}
|
|
|
|
$srcW = imagesx($image);
|
|
$srcH = imagesy($image);
|
|
|
|
if ($crop) {
|
|
[$w, $h] = array_map('intval', explode('x', $spec));
|
|
$srcRatio = $srcW / $srcH;
|
|
$dstRatio = $w / $h;
|
|
if ($srcRatio > $dstRatio) {
|
|
$cropH = $srcH;
|
|
$cropW = (int) round($srcH * $dstRatio);
|
|
} else {
|
|
$cropW = $srcW;
|
|
$cropH = (int) round($srcW / $dstRatio);
|
|
}
|
|
$x = (int) (($srcW - $cropW) / 2);
|
|
$y = (int) (($srcH - $cropH) / 2);
|
|
$out = imagecreatetruecolor($w, $h);
|
|
imagecopyresampled($out, $image, 0, 0, $x, $y, $w, $h, $cropW, $cropH);
|
|
imagejpeg($out, $dest, $quality);
|
|
echo "{$dest} ({$w}x{$h})\n";
|
|
exit(0);
|
|
}
|
|
|
|
foreach (explode(',', $spec) as $width) {
|
|
$w = min((int) $width, $srcW); // nie hochskalieren
|
|
$h = (int) round($srcH * $w / $srcW);
|
|
$out = imagecreatetruecolor($w, $h);
|
|
imagecopyresampled($out, $image, 0, 0, 0, 0, $w, $h, $srcW, $srcH);
|
|
$file = "{$dest}-{$w}.jpg";
|
|
imagejpeg($out, $file, $quality);
|
|
echo "{$file} ({$w}x{$h}, " . round(filesize($file) / 1024) . " KB)\n";
|
|
}
|