fix: decode .bin to PNG via PPM blob, not importImagePixels
CI / test (push) Has been cancelled

The Imagick extension on the server (3.7+) requires importImagePixels
to receive an array of ints, not a string blob, so the previous code
500'd. Wrap the raw RGB bytes in a PPM (P6) header and let Imagick
decode it via readImageBlob — same result, no 70 MB-array detour.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-06 13:16:58 -04:00
parent b0c27a9332
commit c2b208f103
+6 -2
View File
@@ -243,9 +243,13 @@ class DeviceApiController extends AbstractController
}
}
// Wrap the raw RGB bytes in a PPM (P6) header so Imagick can decode the
// blob directly. importImagePixels would also work but its current
// signature requires an array of ints, which is ~70 MB for an 800×480.
$ppm = "P6\n{$width} {$height}\n255\n" . $rgb;
$im = new \Imagick();
$im->newImage($width, $height, new \ImagickPixel('white'));
$im->importImagePixels(0, 0, $width, $height, 'RGB', \Imagick::PIXEL_CHAR, $rgb);
$im->readImageBlob($ppm);
$im->setImageFormat('png');
$im->writeImage($pngPath);
$im->destroy();