Noch schneller (0.46.0)
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 7m38s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 8m0s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 11m51s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 12m15s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 13m27s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 13m42s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 16m0s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 15m20s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 56s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m14s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 7m38s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 8m0s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 11m51s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 12m15s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 13m27s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 13m42s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 16m0s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 15m20s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 56s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m14s
- Erscheinungsbild: große Fotos (Anmeldung, Titelbild) beim Speichern als WebP ≤ 2400 px; Migration verkleinert vorhandene einmal - Vite: Grundgerüst und UI-Bausteine als gemeinsame Dateien (Startseite 34 statt 58 Skripte) - Plugin-Oberflächen: Kopie nach public/ erneuert sich bei neuem Build (Fingerabdruck von dist/inhaus.json), auch ohne neue Version Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
2b8769aa23
commit
03e31f42b5
422 changed files with 1429 additions and 1712 deletions
|
|
@ -116,9 +116,31 @@ class Theme
|
|||
SvgSanitizer::sanitizeFile($theme[$image]);
|
||||
}
|
||||
|
||||
// Große Fotos (Anmeldung, Titelbild) verkleinern – sie laden auf vielen Seiten mit
|
||||
$theme = app(ThemePhotos::class)->optimizeAll($theme);
|
||||
|
||||
$this->settings->set(self::DRAFT, $theme);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schon veröffentlichte und im Entwurf liegende Fotos nachträglich verkleinern (Migration).
|
||||
*/
|
||||
public function optimizePhotos(): void
|
||||
{
|
||||
$photos = app(ThemePhotos::class);
|
||||
$published = $this->settings->get(self::PUBLISHED);
|
||||
|
||||
if (is_array($published)) {
|
||||
$this->settings->set(self::PUBLISHED, $photos->optimizeAll($published));
|
||||
}
|
||||
|
||||
$draft = $this->settings->get(self::DRAFT);
|
||||
|
||||
if (is_array($draft)) {
|
||||
$this->settings->set(self::DRAFT, $photos->optimizeAll($draft));
|
||||
}
|
||||
}
|
||||
|
||||
public function discardDraft(): void
|
||||
{
|
||||
$this->settings->set(self::DRAFT, null);
|
||||
|
|
|
|||
80
app/Support/Theme/ThemePhotos.php
Normal file
80
app/Support/Theme/ThemePhotos.php
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
namespace App\Support\Theme;
|
||||
|
||||
use App\Support\Images;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Intervention\Image\Drivers\Gd\Driver;
|
||||
use Intervention\Image\Encoders\WebpEncoder;
|
||||
use Intervention\Image\ImageManager;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Fotos im Erscheinungsbild (Hintergrund der Anmeldung, Standard-Titelbild) werden oft in voller
|
||||
* Kameragröße hochgeladen – mehrere MB, die auf jeder Seite mitgeladen würden. Große Dateien
|
||||
* werden deshalb als WebP mit höchstens 2400 px abgelegt. Logos bleiben unverändert.
|
||||
*/
|
||||
class ThemePhotos
|
||||
{
|
||||
/** Bildfelder, die Fotos sind (Logos, Symbole und Platzhalter bleiben, wie sie sind) */
|
||||
public const FIELDS = ['login_image', 'profile_cover'];
|
||||
|
||||
public const MAX_EDGE = 2400;
|
||||
|
||||
/** Ab dieser Größe wird verkleinert (kleinere Dateien sind bereits sparsam) */
|
||||
public const MAX_BYTES = 450 * 1024;
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $theme
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function optimizeAll(array $theme): array
|
||||
{
|
||||
foreach (self::FIELDS as $field) {
|
||||
if (is_string($theme[$field] ?? null) && $theme[$field] !== '') {
|
||||
$theme[$field] = $this->optimize($theme[$field]);
|
||||
}
|
||||
}
|
||||
|
||||
return $theme;
|
||||
}
|
||||
|
||||
/** Liefert den (ggf. neuen) Pfad – bei Fehlern den alten */
|
||||
public function optimize(string $path): string
|
||||
{
|
||||
$disk = Storage::disk('uploads');
|
||||
$extension = strtolower(pathinfo($path, PATHINFO_EXTENSION));
|
||||
|
||||
if (! in_array($extension, ['jpg', 'jpeg', 'png', 'webp'], true) || ! $disk->exists($path)) {
|
||||
return $path;
|
||||
}
|
||||
|
||||
try {
|
||||
$local = $disk->path($path);
|
||||
$size = $disk->size($path);
|
||||
[$width, $height] = @getimagesize($local) ?: [0, 0];
|
||||
|
||||
if ($size <= self::MAX_BYTES && max($width, $height) <= self::MAX_EDGE) {
|
||||
return $path;
|
||||
}
|
||||
|
||||
Images::raiseMemoryLimitFor($local);
|
||||
$image = ImageManager::usingDriver(Driver::class)->decodePath($local)->scaleDown(self::MAX_EDGE, self::MAX_EDGE);
|
||||
$encoded = $image->encode(new WebpEncoder(quality: 80))->toString();
|
||||
|
||||
if (strlen($encoded) >= $size) {
|
||||
return $path; // nichts gewonnen
|
||||
}
|
||||
|
||||
$target = 'theme/'.Str::ulid().'.webp';
|
||||
$disk->put($target, $encoded);
|
||||
|
||||
return $target;
|
||||
} catch (Throwable $e) {
|
||||
report($e);
|
||||
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue