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.
This commit is contained in:
Paul Kaplan 2019-12-09 16:03:13 -05:00 committed by GitHub
parent e086c4260e
commit 9491b7eb09
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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 */,