The following code takes an image, copies it into a canvas (so it can be modified), then it turns it into an image again:
const image = this.markerEditorEl.components.screenshot.getCanvas('perspective').toDataURL()
var canvas = document.getElementById('test-canvas')
var context = canvas.getContext('2d')
var imageObj = new Image()
imageObj.onload = function () {
// set values
const sourceWidth = cropWidth
const sourceHeight = cropHeight
const sourceX = (width / 2) - (sourceWidth / 2)
const sourceY = (height / 2) - (sourceHeight / 2)
const destWidth = cropWidth
const destHeight = cropHeight
const destX = 0
const destY = 0
context.drawImage(imageObj, sourceX, sourceY, sourceWidth, sourceHeight, destX, destY, destWidth, destHeight)
window.location = canvas.toDataURL()
}
imageObj.src = image
As you can see, I'm trying to download the image automatically: window.location = canvas.toDataURL()
. However, this doesn't work. I get:
Not allowed to navigate top frame to data URL: data:image/png;base64,iVBORw0KG.......
What's the correct way of doing this? I need the image to be automatically downloaded to the user's computer.