php - readimageblob: Fatal Error when converting SVG into PNG -


i'm trying use image-magick php convert svg text png image. svg chart generated nvd3 , i'd allow users download image.

basically, i'm sending svg data, encoded json php handler supposed output png image.

but, throws following error:

fatal error: uncaught exception 'imagickexception' message 'no decode delegate image format `' @ blob.c/blobtoimage/347' in svg2png.php:4 stack trace: #0 svg2png.php(4): imagick->readimageblob(' 

the php script converting image:

<?php     /* derived in part from: http://stackoverflow.com/a/4809562/937891 */     $svg=json_decode($_request["svgdata"]);     $im=new imagick();     $im->readimageblob($svg);     $im->setimageformat("png24");     header("content-type: image/png");     $thumbnail = $im->getimageblob();     echo $thumbnail; ?> 

html:

<form id="exportspendtrendtrigger" method="post" action="svg2png.php" target="_blank">     <input id="exportspendtrendsvgdata" type="hidden" name="svgdata" />     <input type="submit" class="btn" value="export" /> </form> <div id="spendtrend">     <svg></svg> </div> 

jquery:

exportspendtrend = function (e) {     //show user png-image version download     $("#exportspendtrendsvgdata").val( json.stringify($("#spendtrend").html().trim()) ); }  $("#exportspendtrendtrigger").on("submit", exportspendtrend); 

example svg, generated nvd3: http://pastebin.com/z3tvdk16

this on ubuntu server php 5.3 , imagick

svg file text structure needs specified readimageblob decode file. prepend <?xml version="1.0" encoding="utf-8" standalone="no"?> variable having svg text.

$svg = '<?xml version="1.0" encoding="utf-8" standalone="no"?>'.$svg; 

and go.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -