ger*_*ick 10 javascript php svg raphael
我的raphaeljs导出插件有问题(https://github.com/ElbertF/Raphael.Export).在路径元素中我使用属性fill作为源我给图像url填充.但是当我将它导出到SVG时,我看到了一个路径元素定义,但是当我将它导出到PNG时,我再也看不到了.
所以在我的应用程序中,我添加了一个attr这样的path元素:
paper.path("M 195 10 L 300 L 195 z").attr({'stroke-width': 0,'fill': 'url(images/alfen/02/murek.png)'});
Run Code Online (Sandbox Code Playgroud)
我用它导出 paper.toSVG()
在我的SVG中,我找到了一条路径:
<path transform="matrix(1,0,0,1,0,0)" fill="url(images/alfen/02/murek.png)" stroke="#000" d="M203,183.94389438943895L948,183.94389438943895L948,195L203,195Z" stroke-width="0"></path>
Run Code Online (Sandbox Code Playgroud)
但是当我将其转换为PNG时:
<?php
$json = $_POST['json'];
$output = str_replace('\"','"',$json);
$filenameSVG = 'test';
file_put_contents("$filenameSVG.svg", $output);
$konwert = "convert $filenameSVG.svg $filenameSVG.jpg";
system($konwert);
Run Code Online (Sandbox Code Playgroud)
我无法找到满足我背景的这条道路.有人可以帮忙吗?
如果您能够正确输出 svg,但无法在 php 中输出 png,则需要检查以下几项内容。
$output = str_replace('\"','"',$json);$output = str_replace('\"','"',$json['filename_and_path']);如果您返回的 json 是单行,那么可能是更好的处理方法——即将其作为字符串发布,甚至用数组和索引返回每个字符串。对于这个东西:
$konwert = "convert $filenameSVG.svg $filenameSVG.jpg";
system($konwert);
Run Code Online (Sandbox Code Playgroud)
您可能没有system()在字符串中输入有效的变量。为了确保我建议正确连接字符串,例如:
$konwert = "convert".$filenameSVG.".svg ".$filenameSVG.".jpg";
Run Code Online (Sandbox Code Playgroud)
您还需要服务器上文件的绝对文件路径才能执行命令,否则它将找不到该文件。显然,只有当这两个文件位于项目的根目录中时,该代码$konwert = "convert".$filenameSVG.".svg ".$filenameSVG.".jpg";才适用于您。
我也不认为你应该system()在这种情况下使用。我的理解是你应该用于passthru()处理图像二进制文件。还有,exec()但实际上,我认为你在这里需要的是passthru()。请参阅: http: //www.php.net/manual/en/function.passthru.php