{"record":{"id":"a66fef1d5dd84be5","repo":"DenverCoder1/github-readme-streak-stats","slug":"500-failed-to-convert-svg-to-png-error","errorCode":"500","errorMessage":"Failed to convert SVG to PNG: {$error}","messagePattern":"Failed to convert SVG to PNG: (.+?)","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":500,"severity":"error","filePath":"src/card.php","lineNumber":795,"sourceCode":"    $svg = str_replace(\"\\n\", \" \", $svg);\n\n    // escape svg for shell\n    $svg = escapeshellarg($svg);\n\n    // `--pipe`: read input from pipe (stdin)\n    // `--export-filename -`: write output to stdout\n    // `-w 495 -h 195`: set width and height of the output image\n    // `--export-type png`: set the output format to PNG\n    $cmd = \"echo {$svg} | inkscape --pipe --export-filename - -w {$cardWidth} -h {$cardHeight} --export-type png\";\n\n    // convert svg to png\n    $png = shell_exec($cmd); // skipcq: PHP-A1009\n\n    // check if the conversion was successful\n    if (empty($png)) {\n        // `2>&1`: redirect stderr to stdout\n        $error = shell_exec(\"$cmd 2>&1\"); // skipcq: PHP-A1009\n        throw new InvalidArgumentException(\"Failed to convert SVG to PNG: {$error}\", 500);\n    }\n\n    // return the generated png\n    return $png;\n}\n\n/**\n * Return headers and response based on type\n *\n * @param string|array $output The stats (array) or error message (string) to display\n * @param array<string,string>|NULL $params Request parameters\n * @param int $errorCode The HTTP error code (used for JSON responses)\n * @return array The Content-Type header and the response body, and status code in case of an error\n */\nfunction generateOutput(string|array $output, ?array $params = null, int $errorCode = 200): array\n{\n    $params = $params ?? $_REQUEST;\n","sourceCodeStart":777,"sourceCodeEnd":813,"githubUrl":"https://github.com/DenverCoder1/github-readme-streak-stats/blob/70dd50f921097927dc8314ac33a04b010a09924d/src/card.php#L777-L813","documentation":"convertSvgToPng() shells out to an external SVG-to-PNG converter (via shell_exec). If the command produces no stdout output, the library treats the conversion as failed and throws InvalidArgumentException with the converter's stderr text and code 500.","triggerScenarios":"The external converter binary is missing or not on PATH, is misconfigured, receives an invalid SVG, or runs out of memory, causing shell_exec to return empty output.","commonSituations":"Deployment environments without the required tool (e.g. rsvg-convert/inkscape/convert) installed; missing system libraries; an upstream SVG that the converter cannot parse.","solutions":["Install the external SVG conversion tool used by the command (e.g. rsvg-convert or ImageMagick) and confirm it is on PATH","Run the shell command manually to see the real error output","Verify the SVG input is valid XML and renders locally","Check permissions and available memory for the conversion process"],"exampleFix":"// before (on server)\n// rsvg-convert not installed\n// after (Ubuntu/Debian)\n// sudo apt-get install librsvg2-bin","handlingStrategy":"try-catch","validationCode":"if (shell_exec(\"command -v rsvg-convert\") === null) { die(\"SVG converter binary not installed\"); }","typeGuard":null,"tryCatchPattern":"try { $png = convertSvgToPng($svg); } catch (InvalidArgumentException $e) { error_log($e->getMessage()); http_response_code(500); echo \"PNG conversion failed\"; }","preventionTips":["Verify the converter binary exists during deployment health checks","Validate SVG input before conversion","Pin and document the converter dependency in your install scripts"],"tags":["php","shell-exec","svg","png","external-tool"],"backgroundTag":"http-request-failed","analyzedSha":"70dd50f921097927dc8314ac33a04b010a09924d","analyzedAt":"2026-09-15T02:40:51.909Z","contentChangedAt":"2026-09-15T02:40:51.909Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}