Spaces:
Runtime error
Runtime error
fixed images
Browse files
frontend/src/lib/App.svelte
CHANGED
@@ -66,20 +66,23 @@
|
|
66 |
ctxCrop.restore();
|
67 |
|
68 |
// create black image
|
69 |
-
tempCanvasCtx.fillStyle = '
|
70 |
tempCanvasCtx.fillRect(0, 0, 512, 512);
|
71 |
|
72 |
// create Mask
|
73 |
ctxMask.save();
|
74 |
// ctxMask.clearRect(0, 0, 512, 512);
|
75 |
ctxMask.drawImage(canvasCrop, 0, 0, 512, 512);
|
76 |
-
ctxMask.globalCompositeOperation = 'source-
|
77 |
ctxMask.drawImage(tempCanvas, 0, 0);
|
78 |
ctxMask.restore();
|
79 |
|
|
|
80 |
tempCanvasCtx.fillStyle = 'white';
|
81 |
tempCanvasCtx.fillRect(0, 0, 512, 512);
|
82 |
//random pixels
|
|
|
|
|
83 |
// const imageData = tempCanvasCtx.getImageData(0, 0, 512, 512);
|
84 |
// const pix = imageData.data;
|
85 |
// for (let i = 0, n = pix.length; i < n; i += 4) {
|
@@ -92,12 +95,16 @@
|
|
92 |
tempCanvasCtx.drawImage(canvasCrop, 0, 0, 512, 512);
|
93 |
//convert canvas to base64
|
94 |
const base64Crop = tempCanvas.toDataURL('image/png');
|
|
|
95 |
|
96 |
-
tempCanvasCtx.
|
|
|
97 |
tempCanvasCtx.fillRect(0, 0, 512, 512);
|
98 |
tempCanvasCtx.drawImage(mask, 0, 0, 512, 512);
|
99 |
//convert canvas to base64
|
100 |
const base64Mask = tempCanvas.toDataURL('image/png');
|
|
|
|
|
101 |
|
102 |
return { image: base64Crop, mask: base64Mask };
|
103 |
}
|
|
|
66 |
ctxCrop.restore();
|
67 |
|
68 |
// create black image
|
69 |
+
tempCanvasCtx.fillStyle = 'white';
|
70 |
tempCanvasCtx.fillRect(0, 0, 512, 512);
|
71 |
|
72 |
// create Mask
|
73 |
ctxMask.save();
|
74 |
// ctxMask.clearRect(0, 0, 512, 512);
|
75 |
ctxMask.drawImage(canvasCrop, 0, 0, 512, 512);
|
76 |
+
ctxMask.globalCompositeOperation = 'source-out';
|
77 |
ctxMask.drawImage(tempCanvas, 0, 0);
|
78 |
ctxMask.restore();
|
79 |
|
80 |
+
tempCanvasCtx.save();
|
81 |
tempCanvasCtx.fillStyle = 'white';
|
82 |
tempCanvasCtx.fillRect(0, 0, 512, 512);
|
83 |
//random pixels
|
84 |
+
// tempCanvasCtx.filter = 'blur(4px)';
|
85 |
+
|
86 |
// const imageData = tempCanvasCtx.getImageData(0, 0, 512, 512);
|
87 |
// const pix = imageData.data;
|
88 |
// for (let i = 0, n = pix.length; i < n; i += 4) {
|
|
|
95 |
tempCanvasCtx.drawImage(canvasCrop, 0, 0, 512, 512);
|
96 |
//convert canvas to base64
|
97 |
const base64Crop = tempCanvas.toDataURL('image/png');
|
98 |
+
tempCanvasCtx.restore();
|
99 |
|
100 |
+
tempCanvasCtx.save();
|
101 |
+
tempCanvasCtx.fillStyle = 'black';
|
102 |
tempCanvasCtx.fillRect(0, 0, 512, 512);
|
103 |
tempCanvasCtx.drawImage(mask, 0, 0, 512, 512);
|
104 |
//convert canvas to base64
|
105 |
const base64Mask = tempCanvas.toDataURL('image/png');
|
106 |
+
tempCanvasCtx.restore();
|
107 |
+
|
108 |
|
109 |
return { image: base64Crop, mask: base64Mask };
|
110 |
}
|
frontend/src/lib/Canvas.svelte
CHANGED
@@ -68,8 +68,8 @@
|
|
68 |
const images = [...imagesList.toImmutable()].sort((a, b) => a.date - b.date)
|
69 |
images
|
70 |
.forEach(({ imgURL, position }) => {
|
71 |
-
console.log(imgURL, position);
|
72 |
const img = new Image();
|
|
|
73 |
img.onload = () => {
|
74 |
canvasCtx.drawImage(img, position.x, position.y, img.width, img.height);
|
75 |
};
|
|
|
68 |
const images = [...imagesList.toImmutable()].sort((a, b) => a.date - b.date)
|
69 |
images
|
70 |
.forEach(({ imgURL, position }) => {
|
|
|
71 |
const img = new Image();
|
72 |
+
img.crossOrigin = 'anonymous';
|
73 |
img.onload = () => {
|
74 |
canvasCtx.drawImage(img, position.x, position.y, img.width, img.height);
|
75 |
};
|