fix: pint

This commit is contained in:
Benjamin Nussbaum 2025-09-15 19:24:31 +02:00
parent e65473f932
commit 88e10101b8
3 changed files with 50 additions and 31 deletions

View file

@ -7,11 +7,11 @@ use App\Models\Device;
use App\Models\DeviceModel;
use App\Models\Plugin;
use Exception;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
use Imagick;
use ImagickException;
use ImagickPixel;
use Log;
use Ramsey\Uuid\Uuid;
use RuntimeException;
use Spatie\Browsershot\Browsershot;
@ -63,6 +63,15 @@ class ImageGenerationService
}
}
// Validate that the PNG file was created and is valid
if (! file_exists($pngPath)) {
throw new RuntimeException('PNG file was not created: '.$pngPath);
}
if (filesize($pngPath) === 0) {
throw new RuntimeException('PNG file is empty: '.$pngPath);
}
// Convert image based on DeviceModel settings or fallback to device settings
self::convertImage($pngPath, $bmpPath, $imageSettings);
@ -293,6 +302,7 @@ class ImageGenerationService
*/
private static function convertToBmpImageMagick(string $pngPath, string $bmpPath): void
{
try {
$imagick = new Imagick($pngPath);
$imagick->setImageType(Imagick::IMGTYPE_GRAYSCALE);
$imagick->quantizeImage(2, Imagick::COLORSPACE_GRAY, 0, true, false);
@ -301,6 +311,10 @@ class ImageGenerationService
$imagick->setFormat('BMP3');
$imagick->writeImage($bmpPath);
$imagick->clear();
} catch (ImagickException $e) {
Log::error('ImageMagick conversion failed for PNG: '.$pngPath.' - '.$e->getMessage());
throw $e;
}
}
/**
@ -308,6 +322,7 @@ class ImageGenerationService
*/
private static function convertToPngImageMagick(string $pngPath, ?int $width, ?int $height, ?int $rotate, $quantize = true): void
{
try {
$imagick = new Imagick($pngPath);
if ($width !== 800 || $height !== 480) {
$imagick->resizeImage($width, $height, Imagick::FILTER_LANCZOS, 1, true);
@ -328,6 +343,10 @@ class ImageGenerationService
$imagick->setFormat('png');
$imagick->writeImage($pngPath);
$imagick->clear();
} catch (ImagickException $e) {
Log::error('ImageMagick conversion failed for PNG: '.$pngPath.' - '.$e->getMessage());
throw $e;
}
}
public static function cleanupFolder(): void

View file

@ -41,7 +41,7 @@ it('loads plugins from catalog URL', function () {
'byos' => [
'byos_laravel' => [
'compatibility' => true,
]
],
],
'logo_url' => 'https://example.com/logo.png',
],