合并来自Raphael svg的图片
试图创造
第1步 – 让用户通过Ajax,Raphael和Raphael freetransform上传图像。
步骤2 – 单击按钮以显示合并上载图像中的一个图像。 (问题):我发现有关转换Raphael svg 1 2 3的类似post,
所以我也使用Canvg,但得到console.log: Resource interpreted as image but transferred with MIME type text/html
error: image "" not found
。
请帮我找到解决方法。 或任何线索如何达到相同的目标(将上传的几个Raphael svg图像转换为一个png / jpeg)?
谢谢!
步骤1
// upload images and ajax show in page var paper = Raphael($('.upload_img')[0], 400, 200); $('.upload_btn').click(function(){ ... $.ajax({ type: "POST", url: "index.php", data: fd, processData: false, contentType: false, success: function(html){ var session = ..., file = ... type = ...; function register(el) { // toggle handle }; var img = new Image(); img.onload = function(){ var r_img = paper.image('img/product/tmp/'+session+'/'+file+type, 0, 0, 200, 200); register(r_img); }; img.src = 'img/product/tmp/'+session+'/'+file+type; } }); });
第2步
// merge and show $('.merge_btn').click(function(){ var upload_svg = $('.upload_img').html(); canvg('canvas', upload_svg); console.log('upload_svg'+upload_svg); // // and get error }); // These code If toggle show Raphael freetransform svg handle, it is work convert several svg handle to one image. but still not found upload image to merge
如果我没有误会, canvg
函数需要第二个参数是一个包含图像文件路径的String
。 但是在第2步中,您的代码会:
var upload_svg = $('.upload_img').html(); // **** this does not return the image path canvg('canvas', upload_svg);
我建议你尝试类似的东西:
var upload_svg = $('.upload_img').attr('src'); canvg('canvas', upload_svg);
这将解释错误 – Resource interpreted as image but transferred with MIME type text/html
– 它需要一个图像但接收空白HTML
。 其余的代码似乎很好。