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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度