请帮忙。<image/>
直到最近,我一直在使用php Imagick库将svg(包括标记中嵌入的png图像)成功转换为png图像。我猜在对ubuntu进行一些更新之后,嵌入的png图像就停止出现在svg转换的图像中了。
$svg = json_decode($_POST['svgdata']);
$svg = '<?xml version="1.1" encoding="UTF-8" standalone="no"?>'.$svg;
$im = new Imagick();
$success = $im->readImageBlob($svg);
$im->setImageFormat("png24");
$im->writeImage('png_img/var.png');
如果我回显$ svg,它将为我提供正确的图像。
而保存的图像是。
以供参考:
$svg = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns:xlink="http://www.w3.org/1999/xlink" style="overflow: hidden; position: relative; -moz-user-select: text;" xmlns="http://www.w3.org/2000/svg" width="794" version="1.1" height="122">
<image class="barcode" style="-moz-user-select: text;" xlink:href="images/52aab69d.png" preserveAspectRatio="none" height="40" width="266" y="30" x="380"></image>
<rect class="ref" style="-moz-user-select: text;" stroke="#000" fill="#000000" ry="0" rx="0" r="0" height="18" width="18" y="15" x="10"></rect></svg>';
我找到了解决方案。我必须以完全不同的方式来做。我从->将图像转换为base64寻求帮助。
现在,图像已嵌入SVG中,php代码成功将svg转换为PNG图像。只是将图像路径替换为base64字符串。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句