dongmiyi8220 2012-06-18 21:05
浏览 136
已采纳

将raphaeljs导出为jpg且路径背景为图像时出错

I have a problem with raphaeljs export plugin ( https://github.com/ElbertF/Raphael.Export ). in a path element I use attribute fill and as a source I give a image url to fullfill. But when I export this to SVG I see a path element definition, but when I export it to PNG, I do not see again.

So in my app I add an attr to path element like this:

paper.path("M 195 10 L 300  L 195 z").attr({'stroke-width': 0,'fill': 'url(images/alfen/02/murek.png)'});

and I export this with paper.toSVG()

and in my SVG I find a path:

<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>

But when I transform this to PNG with:

<?php 
    $json        = $_POST['json'];
    $output      = str_replace('\"','"',$json);
    $filenameSVG = 'test';

    file_put_contents("$filenameSVG.svg", $output);

    $konwert = "convert $filenameSVG.svg $filenameSVG.jpg";

    system($konwert);

I cannot find this path fulfilled with my background. Can anybody help?

  • 写回答

2条回答 默认 最新

  • duan35557593 2014-04-13 16:44
    关注

    If you're able to get correct output to svg but it fails going to png in php there are several things you'll need to check.

    • As a sanity check make sure your $_POST['json'] is not returning malformed json
    • The next line in your php confuses me: $output = str_replace('\"','"',$json);
    • It could be that the json you're returning is a single object, but I'm still not sure why you are searching the entire file and not looking for a specific nested object like $output = str_replace('\"','"',$json['filename_and_path']); and if the json you return IS a single line, there may be better ways to handle it -- i.e. post it as a string or even return each one with an array and index.

    And for this stuff:

    $konwert = "convert $filenameSVG.svg $filenameSVG.jpg";
    system($konwert);
    

    You may not be feeding system() with valid variables in your string. To be sure I recommend properly concatenating the string like:

    $konwert = "convert".$filenameSVG.".svg ".$filenameSVG.".jpg";
    

    You're also going to need the absolute filepath to the file on your server to execute the command on or else it won't find the file. The code $konwert = "convert".$filenameSVG.".svg ".$filenameSVG.".jpg"; is obviously only going to work for you if those two files are located in the root directory of your project.

    I also don't think you should be using system() in this instance. My understanding is you should be using passthru() for dealing with image binaries. There's also exec() but really, I think what you need here is passthru(). See: http://www.php.net/manual/en/function.passthru.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作