diff --git a/src/helper/bitmap.js b/src/helper/bitmap.js index 0fa986a2..5b5ec415 100644 --- a/src/helper/bitmap.js +++ b/src/helper/bitmap.js @@ -329,10 +329,10 @@ const getHitBounds = function (raster) { let left = 0; let right = imageData.width; - while (bottom - 1 > top && rowBlank_(imageData, width, bottom - 1)) --bottom; while (top < bottom && rowBlank_(imageData, width, top)) ++top; - while (right - 1 > left && columnBlank_(imageData, width, right - 1, top, bottom)) --right; + while (bottom - 1 > top && rowBlank_(imageData, width, bottom - 1)) --bottom; while (left < right && columnBlank_(imageData, width, left, top, bottom)) ++left; + while (right - 1 > left && columnBlank_(imageData, width, right - 1, top, bottom)) --right; return new paper.Rectangle(left, top, right - left, bottom - top); }; diff --git a/src/hocs/update-image-hoc.jsx b/src/hocs/update-image-hoc.jsx index f7997c5e..ecae4cb6 100644 --- a/src/hocs/update-image-hoc.jsx +++ b/src/hocs/update-image-hoc.jsx @@ -89,9 +89,18 @@ 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. + if (rect.width === 0 || rect.height === 0) { + imageData.sourceWidth = rect.width; + imageData.sourceHeight = rect.height; + } + this.props.onUpdateImage( false /* isVector */, - plasteredRaster.getImageData(rect), + imageData, (ART_BOARD_WIDTH / 2) - rect.x, (ART_BOARD_HEIGHT / 2) - rect.y);