load base64 image with fabric.Image.fromURL

Viewed 11017

I am working with fabric.js inside of backbone.js, and trying to figure out how to load a Base64 image using fabric's command:

fabric.Image.fromURL( 'url', function(img)....

It works fine when I plug in a static url, like:

fabric.Image.fromURL('http://www.domain.com/image.jpg', function(img) {
    img.set({ left: ui.offset.left, top: ui.offset.top});
    canvas.add(img);       
});

but I cannot get a Base64 image to load successfully. How I am I supposed to solve this problem?

3 Answers

All of the above answers are correct. But without an example, the answers aren't obvious.

fabric.Image.fromURL('data:image/png;base64,iVBORw0KGgo....', function(img) {
    img.set({ left: ui.offset.left, top: ui.offset.top});
    canvas.add(img);       
});
Related