mirror of
https://github.com/scratchfoundation/scratch-paint.git
synced 2024-12-23 05:52:42 -05:00
Fix image conversion in firefox and add fallback (#417)
This commit is contained in:
parent
89133f42e5
commit
c00234c1a7
1 changed files with 12 additions and 1 deletions
|
@ -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();
|
||||||
|
|
Loading…
Reference in a new issue