diff --git a/__init__.py b/__init__.py index b0158a3..fda422a 100644 --- a/__init__.py +++ b/__init__.py @@ -50,10 +50,11 @@ class Canvas_Tab: def image_buffer(self, unique_id, mask, canvas, images=None): collected_images = list() - for image in images or []: - i = 255. * image.cpu().numpy() - img = Image.fromarray(np.clip(i, 0, 255).astype(np.uint8)) - collected_images.append(image_to_data_url(img)) + if images is not None: + for image in images: + i = 255. * image.cpu().numpy() + img = Image.fromarray(np.clip(i, 0, 255).astype(np.uint8)) + collected_images.append(image_to_data_url(img)) diff --git a/web/page/bspaint.js b/web/page/bspaint.js index 70c8d71..a91923d 100644 --- a/web/page/bspaint.js +++ b/web/page/bspaint.js @@ -349,6 +349,23 @@ function addNewImage(image) { return(result) } +function addNewLayer(image) { + if (!selectedExport) { + setExportPic(addNewImage(image)); + return; + } + let pic = selectedExport; + if (pic.canvas.width === image.width && pic.canvas.height==image.height) { + const layer = new Layer("generation",pic.canvas); + layer.ctx.drawImage(image,0,0); + console.log("new layer", layer) + console.log(layer.canvas.width, layer.canvas.height) + pic.layers.push(layer); + updateLayerList(); + pic.updateVisualRepresentation(); + } +} + function handleMouseDown(e) { //console.log("mousedown on pic",e); let pic = e.currentTarget.pic; diff --git a/web/page/index.html b/web/page/index.html index 23dcbc2..e2981d9 100644 --- a/web/page/index.html +++ b/web/page/index.html @@ -11,6 +11,16 @@