Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

merge images from Raphael svg

Trying to create
Step 1 - Let users upload images through Ajax, Raphael and Raphael freetransform.

Step 2 - Click button to show one image from merge upload images. (Question): I have found similar post about convert Raphael svg 1 2 3,
so I'm using Canvg too but get console.log: Resource interpreted as image but transferred with MIME type text/html error: image "" not found.

Please help me find how to solve it. or any clue how to reach same goal(convert several Raphael svg images from upload to one png/jpeg) in other way?

Thanks!

Step 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;
        }
    });
});

Step 2

// merge and show
$('.merge_btn').click(function(){
    var upload_svg = $('.upload_img').html();
    canvg('canvas', upload_svg);
    console.log('upload_svg'+upload_svg); //<svg height="200" version="1.1" width="400" xmlns="http://www.w3.org/2000/svg" style="overflow-x: hidden; overflow-y: hidden; position: relative; "><desc></desc><defs></defs><image x="0" y="0" width="200" height="216.91973969631235" preserveAspectRatio="none" href="img/product/tmp/bc4d26ceb620852db36074d351883539/6.jpeg"></image></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
like image 223
vibskov Avatar asked May 15 '13 03:05

vibskov


People also ask

How to merge SVG files online?

Use the “Layers” button to bring one of the SVG files forward and send the other (s) to the back Customize your design by adding captions, icons, frames, effects, or image filters. Click on the “Download” button when you’re done to save your design. Pixelied is the perfect solution if you want to merge SVG files online.

How to convert an SVG file to a JPG?

Draw the lines in the SVG file on it in memory Output that single image as a JPG to the browser. This of course means that you have to be able to interpret SVG...

Can I use SVG/VML to display graphics on a map?

I have an website using SVG/VML (via Raphael JS) setup in a mapping application where the SVG is used to display graphics atop a backdrop map image. This works very well onscreen, and for printing hardcopy maps with overlays. Where this setup falls apart however is when the user wants to save the map image with the SVG overlay to a local .JPG file.

How do I copy and paste between two SVGS?

For example, use Inkscape for Mac (it’s free/open-source). or Adobe Illustrator. Simply open the two SVGs, and copy and paste the content from one to the other and save. Alternatively – you may wish to do it programmatically?


1 Answers

If I'm not mistaking canvg function expects the second parameter to be a String containing the path to your image file. However in step 2 your code does:

    var upload_svg = $('.upload_img').html(); // **** this does not return the image path
    canvg('canvas', upload_svg);

I suggest you try something like:

    var upload_svg = $('.upload_img').attr('src');
    canvg('canvas', upload_svg);

That will explain the error - Resource interpreted as image but transferred with MIME type text/html - it expects an image but receives blank HTML. The rest of the code seems fine.

like image 188
Yotam Omer Avatar answered Sep 22 '22 14:09

Yotam Omer