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?
Try: data:image/jpeg;base64,"+url
. If this doesn't work then maybe your base64
is broken or you might need to tweak the base64
to unit8
conversion technique provided here and add the image data to the image object placed inside the canvas.
Data URI
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);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With