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'])
|
->offsetY($imageSettings['offset_y'])
|
||||||
->outputPath($outputPath);
|
->outputPath($outputPath);
|
||||||
|
|
||||||
|
// Apply dithering if requested by markup
|
||||||
|
$shouldDither = self::markupContainsDitherImage($markup);
|
||||||
|
if ($shouldDither) {
|
||||||
|
$imageStage->dither();
|
||||||
|
}
|
||||||
|
|
||||||
(new TrmnlPipeline())->pipe($browserStage)
|
(new TrmnlPipeline())->pipe($browserStage)
|
||||||
->pipe($imageStage)
|
->pipe($imageStage)
|
||||||
->process();
|
->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
|
public static function cleanupFolder(): void
|
||||||
{
|
{
|
||||||
$activeDeviceImageUuids = Device::pluck('current_screen_image')->filter()->toArray();
|
$activeDeviceImageUuids = Device::pluck('current_screen_image')->filter()->toArray();
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
"ext-simplexml": "*",
|
"ext-simplexml": "*",
|
||||||
"ext-zip": "*",
|
"ext-zip": "*",
|
||||||
"bnussbau/laravel-trmnl-blade": "2.0.*",
|
"bnussbau/laravel-trmnl-blade": "2.0.*",
|
||||||
"bnussbau/trmnl-pipeline-php": "^0.3.0",
|
"bnussbau/trmnl-pipeline-php": "^0.4.0",
|
||||||
"keepsuit/laravel-liquid": "^0.5.2",
|
"keepsuit/laravel-liquid": "^0.5.2",
|
||||||
"laravel/framework": "^12.1",
|
"laravel/framework": "^12.1",
|
||||||
"laravel/sanctum": "^4.0",
|
"laravel/sanctum": "^4.0",
|
||||||
|
|
|
||||||
14
composer.lock
generated
14
composer.lock
generated
|
|
@ -4,7 +4,7 @@
|
||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "d6d201899ecc5b1243e9a481c22c5732",
|
"content-hash": "3d743ce4dc2742c59ed6f9cc8ed36e04",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "aws/aws-crt-php",
|
"name": "aws/aws-crt-php",
|
||||||
|
|
@ -243,16 +243,16 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "bnussbau/trmnl-pipeline-php",
|
"name": "bnussbau/trmnl-pipeline-php",
|
||||||
"version": "0.3.2",
|
"version": "0.4.0",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/bnussbau/trmnl-pipeline-php.git",
|
"url": "https://github.com/bnussbau/trmnl-pipeline-php.git",
|
||||||
"reference": "ead26a45ac919e3f2a5f4a448508a919cd3258d3"
|
"reference": "b58b937f36e55aa7cbd4859cbe7a902bf1050bf8"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/bnussbau/trmnl-pipeline-php/zipball/ead26a45ac919e3f2a5f4a448508a919cd3258d3",
|
"url": "https://api.github.com/repos/bnussbau/trmnl-pipeline-php/zipball/b58b937f36e55aa7cbd4859cbe7a902bf1050bf8",
|
||||||
"reference": "ead26a45ac919e3f2a5f4a448508a919cd3258d3",
|
"reference": "b58b937f36e55aa7cbd4859cbe7a902bf1050bf8",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
|
@ -294,7 +294,7 @@
|
||||||
],
|
],
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/bnussbau/trmnl-pipeline-php/issues",
|
"issues": "https://github.com/bnussbau/trmnl-pipeline-php/issues",
|
||||||
"source": "https://github.com/bnussbau/trmnl-pipeline-php/tree/0.3.2"
|
"source": "https://github.com/bnussbau/trmnl-pipeline-php/tree/0.4.0"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
|
@ -310,7 +310,7 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2025-10-17T12:12:40+00:00"
|
"time": "2025-10-30T11:52:17+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "brick/math",
|
"name": "brick/math",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue