Fix image conversion in firefox and add fallback (#417)

This commit is contained in:
DD Liu 2018-05-02 15:09:05 -04:00 committed by GitHub
parent 89133f42e5
commit c00234c1a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -107,7 +107,18 @@ class PaperCanvas extends React.Component {
paper.project.activeLayer.removeChildren(); paper.project.activeLayer.removeChildren();
this.props.onUpdateImage(); this.props.onUpdateImage();
}; };
img.src = `data:image/svg+xml;charset=utf-8,${svgString}`; img.onerror = () => {
// Fallback if browser does not support SVG data URIs in images.
// The problem with rasterize is that it will anti-alias.
const raster = paper.project.activeLayer.rasterize(72, false /* insert */);
raster.onLoad = () => {
getRaster().drawImage(raster.canvas, raster.bounds.topLeft);
paper.project.activeLayer.removeChildren();
this.props.onUpdateImage();
};
};
// Hash tags will break image loading without being encoded first
img.src = `data:image/svg+xml;utf8,${encodeURIComponent(svgString)}`;
} }
convertToVector () { convertToVector () {
this.props.clearSelectedItems(); this.props.clearSelectedItems();