我在使用 php 扩展 imagick 时遇到问题。我似乎正确安装了它,因为在我的 phpinfo 中出现了扩展 imagick。问题是当我尝试将 svg 转换为 jpg 时出现错误:NoDecodeDelegateForThisImageFormat `' @ error/blob.c/BlobToImage/449我的代码是这个例子的基础: Convert SVG image to PNG with PHPfunction saveSVGToDriveAsPng($svg, $imagepath){// header('Content-type: image/jpeg'); $im = new Imagick(); try { $im->readImageBlob($svg); } catch (ImagickException $e) { echo $svg; echo $e->getMessage(); } /*png settings*/ $im->setImageFormat("png24"); header('Content-type: image/png'); $im->writeImage($imagepath);/*(or .jpg)*/ $im->clear(); $im->destroy();$svg 示例: $svg = '<svg version="1.1" id="Laag_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 1493.9 377" style="enable-background:new 0 0 1493.9 377;" xml:space="preserve"><style type="text/css">.st0{fill:black;}</style><path id="Pelsterplaat_met_tekstrand" class="st0" d="M1493.9,334.5c0,23.5-19,42.5-42.5,42.5H42.5C19,377,0,358,0,334.5v-292 C0,19,19,0,42.5,0h1408.8c23.5,0,42.5,19,42.5,42.5V334.5z M1487.5,44.7c0-23.5-17.7-38.1-41.2-38.1H47.2 C23.7,6.6,6.4,20.9,6.4,44.4v237.9c0,23.5,19,42.5,42.5,42.5H1445c23.5,0,42.5-19,42.5-42.5V44.7z"></path><rect id="PrintAreaBG" x="42.52161654135338" y="328.1251409774436" width="1408.8828947368422" height="45.35639097744361" fill="#cdb27d"></rect><svg id="svg-banner"><text id="text-ontwerp" class="st3 st4 st5" alignment-baseline="middle" text-anchor="middle" y="365" x="730"><tspan id="text1" xml:space="default" fill="rgb(0, 0, 0)" x="730" text-anchor="middle" style="font-family: arial-rounded-mt; text-transform: none; font-size: 40px;">testzooi</tspan> <tspan id="text2" xml:space="default" fill="rgb(255, 255, 255)" x="" text-anchor="middle" style="text-transform: none; font-size: 40px;">Met heel Veel KAAAAASASSS</tspan></text></svg>我希望这段代码基于 svg 将图像写入我的服务器。目前,经过数小时的反复试验,我仍然收到上述错误。
添加回答
举报
0/150
提交
取消