mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-13 15:07:49 +00:00
fix(#103): apply dithering if requested by markup
This commit is contained in:
parent
315fbac261
commit
38e1b6f2a6
3 changed files with 39 additions and 8 deletions
|
|
@ -72,6 +72,12 @@ class ImageGenerationService
|
|||
->offsetY($imageSettings['offset_y'])
|
||||
->outputPath($outputPath);
|
||||
|
||||
// Apply dithering if requested by markup
|
||||
$shouldDither = self::markupContainsDitherImage($markup);
|
||||
if ($shouldDither) {
|
||||
$imageStage->dither();
|
||||
}
|
||||
|
||||
(new TrmnlPipeline())->pipe($browserStage)
|
||||
->pipe($imageStage)
|
||||
->process();
|
||||
|
|
@ -209,6 +215,31 @@ class ImageGenerationService
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect whether the provided HTML markup contains an <img> tag with class "image-dither".
|
||||
*/
|
||||
private static function markupContainsDitherImage(string $markup): bool
|
||||
{
|
||||
if (mb_trim($markup) === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Find <img ... class="..."> (or with single quotes) and inspect class tokens
|
||||
$imgWithClassPattern = '/<img\b[^>]*\bclass\s*=\s*(["\'])(.*?)\1[^>]*>/i';
|
||||
if (! preg_match_all($imgWithClassPattern, $markup, $matches)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($matches[2] as $classValue) {
|
||||
// Look for class token 'image-dither' or 'image--dither'
|
||||
if (preg_match('/(?:^|\s)image--?dither(?:\s|$)/', $classValue)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function cleanupFolder(): void
|
||||
{
|
||||
$activeDeviceImageUuids = Device::pluck('current_screen_image')->filter()->toArray();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue