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
|
public function getColorDepthAttribute(): ?string
|
||||||
{
|
{
|
||||||
if (! $this->bit_depth){
|
if (! $this->bit_depth) {
|
||||||
return null;
|
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\DeviceModel;
|
||||||
use App\Models\Plugin;
|
use App\Models\Plugin;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Imagick;
|
use Imagick;
|
||||||
use ImagickException;
|
use ImagickException;
|
||||||
use ImagickPixel;
|
use ImagickPixel;
|
||||||
use Log;
|
|
||||||
use Ramsey\Uuid\Uuid;
|
use Ramsey\Uuid\Uuid;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use Spatie\Browsershot\Browsershot;
|
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
|
// Convert image based on DeviceModel settings or fallback to device settings
|
||||||
self::convertImage($pngPath, $bmpPath, $imageSettings);
|
self::convertImage($pngPath, $bmpPath, $imageSettings);
|
||||||
|
|
||||||
|
|
@ -293,14 +302,19 @@ class ImageGenerationService
|
||||||
*/
|
*/
|
||||||
private static function convertToBmpImageMagick(string $pngPath, string $bmpPath): void
|
private static function convertToBmpImageMagick(string $pngPath, string $bmpPath): void
|
||||||
{
|
{
|
||||||
$imagick = new Imagick($pngPath);
|
try {
|
||||||
$imagick->setImageType(Imagick::IMGTYPE_GRAYSCALE);
|
$imagick = new Imagick($pngPath);
|
||||||
$imagick->quantizeImage(2, Imagick::COLORSPACE_GRAY, 0, true, false);
|
$imagick->setImageType(Imagick::IMGTYPE_GRAYSCALE);
|
||||||
$imagick->setImageDepth(1);
|
$imagick->quantizeImage(2, Imagick::COLORSPACE_GRAY, 0, true, false);
|
||||||
$imagick->stripImage();
|
$imagick->setImageDepth(1);
|
||||||
$imagick->setFormat('BMP3');
|
$imagick->stripImage();
|
||||||
$imagick->writeImage($bmpPath);
|
$imagick->setFormat('BMP3');
|
||||||
$imagick->clear();
|
$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
|
private static function convertToPngImageMagick(string $pngPath, ?int $width, ?int $height, ?int $rotate, $quantize = true): void
|
||||||
{
|
{
|
||||||
$imagick = new Imagick($pngPath);
|
try {
|
||||||
if ($width !== 800 || $height !== 480) {
|
$imagick = new Imagick($pngPath);
|
||||||
$imagick->resizeImage($width, $height, Imagick::FILTER_LANCZOS, 1, true);
|
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);
|
if ($rotate !== null && $rotate !== 0) {
|
||||||
}
|
$imagick->rotateImage(new ImagickPixel('black'), $rotate);
|
||||||
|
}
|
||||||
|
|
||||||
$imagick->setImageType(Imagick::IMGTYPE_GRAYSCALE);
|
$imagick->setImageType(Imagick::IMGTYPE_GRAYSCALE);
|
||||||
$imagick->setOption('dither', 'FloydSteinberg');
|
$imagick->setOption('dither', 'FloydSteinberg');
|
||||||
|
|
||||||
if ($quantize) {
|
if ($quantize) {
|
||||||
$imagick->quantizeImage(2, Imagick::COLORSPACE_GRAY, 0, true, false);
|
$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
|
public static function cleanupFolder(): void
|
||||||
|
|
|
||||||
|
|
@ -39,9 +39,9 @@ it('loads plugins from catalog URL', function () {
|
||||||
'zip_url' => 'https://example.com/plugin.zip',
|
'zip_url' => 'https://example.com/plugin.zip',
|
||||||
],
|
],
|
||||||
'byos' => [
|
'byos' => [
|
||||||
'byos_laravel' => [
|
'byos_laravel' => [
|
||||||
'compatibility' => true,
|
'compatibility' => true,
|
||||||
]
|
],
|
||||||
],
|
],
|
||||||
'logo_url' => 'https://example.com/logo.png',
|
'logo_url' => 'https://example.com/logo.png',
|
||||||
],
|
],
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue