Will describe app at first.
I have drawing area. I can add to it different images and apply few filters to them(brightness, hue-rotate, etc.). After editing is ready I should save result to server as image.
During investigation I found few possible solutions
- Using fabricjs filters. The problem is that performance is not so good as I need, especially on mobile devices.
Using css3 filters. The idea was to use css3 filters for interface and then use fabricjs filters when we render final result. This idea was rejected because anyway we need another solution for other browsers, and it is hard to make filters work identically.
Using svg filters. I stopped on svg filters with next realization:
3.1 I add svg element on drawing area and apply svg filters to it.
3.2 When user try to save result I generate svg xml and create base64 image
'data:image/svg+xml;base64,' + window.btoa(this.getSvg());
3.3 I draw this svg on canvas. And try to save result
resultCanvas.toDataURL()
This solution worked in almost all modern browsers with good performance. But it do not work on ios safari because canvas becomes write only after drawing svg and I got Security Error, DOM exception 18.
To prevent this, I was thinking to save svg to server, and draw image from server on canvas. But it also do not work.
I wrote small test:
Tests.supportSvgToPng = function(){
var canvas = document.createElement('canvas'),
svgSrc = 'images/facebook.svg',
support = true;
var image = new Image();
image.src = svgSrc;
document.body.appendChild(canvas);
context = canvas.getContext("2d");
try {
context.drawImage(image, 0, 0);
canvas.toDataURL();
} catch(e) {
console.log(['supportSvgToPng', e.message]);
support = false;
}
canvas.parentNode.removeChild(canvas);
return support;
}
How can I circumvent this limitation?