From 9491b7eb09ed8d4eca8956250f8dcdf5662f7d8f Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Mon, 9 Dec 2019 16:03:13 -0500 Subject: [PATCH] Emit 1x1 blank bitmap data instead of full empty canvas This fixes the issue where you cannot save blank bitmaps in scratch. We were trying to create PNG files which cannot have 0x0 size. --- src/hocs/update-image-hoc.jsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/hocs/update-image-hoc.jsx b/src/hocs/update-image-hoc.jsx index ecae4cb6..a9d3da1e 100644 --- a/src/hocs/update-image-hoc.jsx +++ b/src/hocs/update-image-hoc.jsx @@ -89,14 +89,15 @@ const UpdateImageHOC = function (WrappedComponent) { } } const rect = getHitBounds(plasteredRaster); - const imageData = plasteredRaster.getImageData(rect); - // If the bitmap has a zero width or height, save this information - // since zero isn't a valid value for on imageData objects' widths and heights. + // Use 1x1 instead of 0x0 for getting imageData since paper.js automagically + // returns the full artboard in the case of getImageData(0x0). + // Bitmaps need a non-zero width/height in order to be saved as PNG. if (rect.width === 0 || rect.height === 0) { - imageData.sourceWidth = rect.width; - imageData.sourceHeight = rect.height; + rect.width = rect.height = 1; } + + const imageData = plasteredRaster.getImageData(rect); this.props.onUpdateImage( false /* isVector */,