javascript - How to convert canvas to SVG with embedded image base64 in fabricjs -
i have fabricjs canvas image, loaded fabric.image.fromurl()
method.
i need export svg, want export image embedded source in base64, not link.
how can it? way load image source not link?
example code:
loading image:
fabric.image.fromurl('./assets/people.jpg', function (image) { image.set({ left: 10, top: 30 }); canvas.add(image); };
exporting svg:
canvas.tosvg();
in exported svg have:
<image xlink:href="http://localhost:8383/app/assets/people.png" />
but want in base64 like:
<image xlink:href="data:image/png;base64,ivborw0kggoaaaansuheugaaae8aaakucayaaacizzszaaaaaxnsr0iars4c6qaaaarnqu1baacx(...)" />
there no option can achieve this: image has method called 'getsvgsrc';
override this:
fabric.image.prototype.getsvgsrc = function() { return this.todataurlforsvg(); }; fabric.image.prototype.todataurlforsvg = function(options) { var el = fabric.util.createcanvaselement(); el.width = this._element.naturalwidth; el.height = this._element.naturalheight; el.getcontext("2d").drawimage(this._element, 0, 0); var data = el.todataurl(options); return data; };
in way should able obtain integrated image svg.
Comments
Post a Comment