mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-13 15:07:49 +00:00
fix: pint
This commit is contained in:
parent
f7d9618f56
commit
3fecfe14bd
3 changed files with 50 additions and 31 deletions
|
|
@ -27,10 +27,10 @@ final class DeviceModel extends Model
|
|||
|
||||
public function getColorDepthAttribute(): ?string
|
||||
{
|
||||
if (! $this->bit_depth){
|
||||
if (! $this->bit_depth) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->bit_depth . 'bit';
|
||||
return $this->bit_depth.'bit';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,14 +302,19 @@ class ImageGenerationService
|
|||
*/
|
||||
private static function convertToBmpImageMagick(string $pngPath, string $bmpPath): void
|
||||
{
|
||||
$imagick = new Imagick($pngPath);
|
||||
$imagick->setImageType(Imagick::IMGTYPE_GRAYSCALE);
|
||||
$imagick->quantizeImage(2, Imagick::COLORSPACE_GRAY, 0, true, false);
|
||||
$imagick->setImageDepth(1);
|
||||
$imagick->stripImage();
|
||||
$imagick->setFormat('BMP3');
|
||||
$imagick->writeImage($bmpPath);
|
||||
$imagick->clear();
|
||||
try {
|
||||
$imagick = new Imagick($pngPath);
|
||||
$imagick->setImageType(Imagick::IMGTYPE_GRAYSCALE);
|
||||
$imagick->quantizeImage(2, Imagick::COLORSPACE_GRAY, 0, true, false);
|
||||
$imagick->setImageDepth(1);
|
||||
$imagick->stripImage();
|
||||
$imagick->setFormat('BMP3');
|
||||
$imagick->writeImage($bmpPath);
|
||||
$imagick->clear();
|
||||
} catch (ImagickException $e) {
|
||||
Log::error('ImageMagick conversion failed for PNG: '.$pngPath.' - '.$e->getMessage());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -308,26 +322,31 @@ class ImageGenerationService
|
|||
*/
|
||||
private static function convertToPngImageMagick(string $pngPath, ?int $width, ?int $height, ?int $rotate, $quantize = true): void
|
||||
{
|
||||
$imagick = new Imagick($pngPath);
|
||||
if ($width !== 800 || $height !== 480) {
|
||||
$imagick->resizeImage($width, $height, Imagick::FILTER_LANCZOS, 1, true);
|
||||
}
|
||||
if ($rotate !== null && $rotate !== 0) {
|
||||
$imagick->rotateImage(new ImagickPixel('black'), $rotate);
|
||||
}
|
||||
try {
|
||||
$imagick = new Imagick($pngPath);
|
||||
if ($width !== 800 || $height !== 480) {
|
||||
$imagick->resizeImage($width, $height, Imagick::FILTER_LANCZOS, 1, true);
|
||||
}
|
||||
if ($rotate !== null && $rotate !== 0) {
|
||||
$imagick->rotateImage(new ImagickPixel('black'), $rotate);
|
||||
}
|
||||
|
||||
$imagick->setImageType(Imagick::IMGTYPE_GRAYSCALE);
|
||||
$imagick->setOption('dither', 'FloydSteinberg');
|
||||
$imagick->setImageType(Imagick::IMGTYPE_GRAYSCALE);
|
||||
$imagick->setOption('dither', 'FloydSteinberg');
|
||||
|
||||
if ($quantize) {
|
||||
$imagick->quantizeImage(2, Imagick::COLORSPACE_GRAY, 0, true, false);
|
||||
if ($quantize) {
|
||||
$imagick->quantizeImage(2, Imagick::COLORSPACE_GRAY, 0, true, false);
|
||||
}
|
||||
$imagick->setImageDepth(8);
|
||||
$imagick->stripImage();
|
||||
|
||||
$imagick->setFormat('png');
|
||||
$imagick->writeImage($pngPath);
|
||||
$imagick->clear();
|
||||
} catch (ImagickException $e) {
|
||||
Log::error('ImageMagick conversion failed for PNG: '.$pngPath.' - '.$e->getMessage());
|
||||
throw $e;
|
||||
}
|
||||
$imagick->setImageDepth(8);
|
||||
$imagick->stripImage();
|
||||
|
||||
$imagick->setFormat('png');
|
||||
$imagick->writeImage($pngPath);
|
||||
$imagick->clear();
|
||||
}
|
||||
|
||||
public static function cleanupFolder(): void
|
||||
|
|
|
|||
|
|
@ -39,9 +39,9 @@ it('loads plugins from catalog URL', function () {
|
|||
'zip_url' => 'https://example.com/plugin.zip',
|
||||
],
|
||||
'byos' => [
|
||||
'byos_laravel' => [
|
||||
'compatibility' => true,
|
||||
]
|
||||
'byos_laravel' => [
|
||||
'compatibility' => true,
|
||||
],
|
||||
],
|
||||
'logo_url' => 'https://example.com/logo.png',
|
||||
],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue