{"record":{"id":"2adb78d798e0aeb4","repo":"Intervention/image","slug":"failed-to-encode-jxl-format","errorCode":null,"errorMessage":"Failed to encode jxl format","messagePattern":"Failed to encode jxl format","errorType":"exception","errorClass":"EncoderException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Imagick/Encoders/JxlEncoder.php","lineNumber":49,"sourceCode":"\n        // strip meta data\n        if ($this->strip || (is_null($this->strip) && $this->driver()->config()->strip)) {\n            $image->modify(new StripMetaModifier());\n        }\n\n        try {\n            $imagick = clone $image->core()->native();\n            $imagick->setFormat($format);\n            $imagick->setImageFormat($format);\n            $imagick->setCompressionQuality($this->quality);\n            $imagick->setImageCompressionQuality($this->quality);\n\n            $result = new EncodedImage($imagick->getImagesBlob(), 'image/jxl');\n            $imagick->clear();\n\n            return $result;\n        } catch (ImagickException | ImageException $e) {\n            throw new EncoderException('Failed to encode jxl format', previous: $e);\n        }\n    }\n}\n","sourceCodeStart":31,"sourceCodeEnd":53,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Imagick/Encoders/JxlEncoder.php#L31-L53","documentation":"The Imagick driver's JxlEncoder clones the native Imagick object, sets format 'JXL' and the configured quality (src/Drivers/Imagick/Encoders/JxlEncoder.php:38-42), then serializes with getImagesBlob(). Any ImagickException or ImageException is rethrown as EncoderException ('Failed to encode jxl format') with the original as previous. JPEG XL is the newest codec here: it requires ImageMagick 7.1+ built with libjxl, which almost no default distro build has - the previous exception will say 'no encode delegate for this image format'.","triggerScenarios":"Calling toJxl() on the Imagick driver when setFormat('JXL')/setImageFormat('JXL') throws because the JPEG XL coder is absent: php -r \"var_dump((new Imagick())->queryFormats('JXL'));\" returns an empty array. ImageMagick 6.x can never satisfy this call.","commonSituations":"Any Debian/Ubuntu/RHEL default ImageMagick package at the time JXL support was still uncommon; php Docker images; adopting JXL for bandwidth savings and discovering only the developer's locally compiled IM7 supports it.","solutions":["Read $e->getPrevious()->getMessage() to confirm the missing-delegate error.","Check Imagick::queryFormats('JXL') on the failing host and locally to see the capability gap.","Build/install ImageMagick 7.1+ with the libjxl delegate (apt-get install libjxl-dev plus a linked build), then rebuild the imagick extension.","Treat JXL as progressive enhancement: feature-detect at boot and fall back to toWebp() when the coder is missing."],"exampleFix":"// before\n$encoded = $manager->read('art.png')->toJxl();\n\n// after\n$jxlSupported = in_array('JXL', Imagick::queryFormats('JXL'), true);\n$encoded = $jxlSupported ? $manager->read('art.png')->toJxl() : $manager->read('art.png')->toWebp();","handlingStrategy":"validation","validationCode":"$jxlSupported = in_array('JXL', Imagick::queryFormats('JXL'), true);\nif (!$jxlSupported) {\n    throw new RuntimeException('JPEG XL encoding unavailable: ImageMagick 7.1+ with libjxl required');\n}\n$encoded = $image->toJxl();","typeGuard":null,"tryCatchPattern":"try {\n    $encoded = $image->toJxl();\n} catch (EncoderException $e) {\n    $reason = $e->getPrevious()?->getMessage() ?? $e->getMessage();\n    $encoded = $image->toWebp(); // degrade, then log $reason\n}","preventionTips":["Treat JXL as progressive enhancement: detect Imagick::queryFormats('JXL') at boot, fall back to WebP.","Pin a custom ImageMagick 7.1+ build with libjxl in a dedicated image rather than relying on distro packages.","Add a codec-availability endpoint to your service so ops can audit what production can actually encode."],"tags":["jxl","jpeg-xl","imagick","encode","delegate"],"backgroundTag":"imagick-no-encode-delegate","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}