|
|
|
@ -1,4 +1,4 @@
|
|
|
|
function cropCanvasAndExportToPNG (canvas) {
|
|
|
|
function cropCanvasAndExportToPNG (canvas, { errorOnTooSmall } = { errorOnTooSmall: false }) {
|
|
|
|
const ctx = canvas.getContext('2d')
|
|
|
|
const ctx = canvas.getContext('2d')
|
|
|
|
|
|
|
|
|
|
|
|
const width = canvas.width
|
|
|
|
const width = canvas.width
|
|
|
|
@ -33,6 +33,10 @@ function cropCanvasAndExportToPNG (canvas) {
|
|
|
|
croppedCanvas.height = croppedHeight
|
|
|
|
croppedCanvas.height = croppedHeight
|
|
|
|
const croppedCtx = croppedCanvas.getContext('2d')
|
|
|
|
const croppedCtx = croppedCanvas.getContext('2d')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (errorOnTooSmall && (croppedWidth < 20 || croppedHeight < 20)) {
|
|
|
|
|
|
|
|
return Promise.reject(new Error('Image too small'))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
croppedCtx.drawImage(canvas, leftmost, topmost, croppedWidth, croppedHeight, 0, 0, croppedWidth, croppedHeight)
|
|
|
|
croppedCtx.drawImage(canvas, leftmost, topmost, croppedWidth, croppedHeight, 0, 0, croppedWidth, croppedHeight)
|
|
|
|
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|