mirror of
https://github.com/scratchfoundation/scratch-paint.git
synced 2024-12-23 05:52:42 -05:00
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:
parent
e086c4260e
commit
9491b7eb09
1 changed files with 6 additions and 5 deletions
|
@ -89,15 +89,16 @@ const UpdateImageHOC = function (WrappedComponent) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const rect = getHitBounds(plasteredRaster);
|
const rect = getHitBounds(plasteredRaster);
|
||||||
const imageData = plasteredRaster.getImageData(rect);
|
|
||||||
|
|
||||||
// If the bitmap has a zero width or height, save this information
|
// Use 1x1 instead of 0x0 for getting imageData since paper.js automagically
|
||||||
// since zero isn't a valid value for on imageData objects' widths and heights.
|
// 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) {
|
if (rect.width === 0 || rect.height === 0) {
|
||||||
imageData.sourceWidth = rect.width;
|
rect.width = rect.height = 1;
|
||||||
imageData.sourceHeight = rect.height;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const imageData = plasteredRaster.getImageData(rect);
|
||||||
|
|
||||||
this.props.onUpdateImage(
|
this.props.onUpdateImage(
|
||||||
false /* isVector */,
|
false /* isVector */,
|
||||||
imageData,
|
imageData,
|
||||||
|
|
Loading…
Reference in a new issue