Created
August 13, 2019 20:12
-
-
Save yuritoledo/77b2f8f9e8e4b288609b12d47e720cf3 to your computer and use it in GitHub Desktop.
Rotate image and get new base64
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const convert = (src, goToRight) => { | |
const img = new Image() | |
const canvas = document.createElement('canvas') | |
const ctx = canvas.getContext('2d') | |
img.crossOrigin = 'Anonymous' | |
img.onload = () => { | |
canvas.width = img.width | |
canvas.height = img.height | |
goToRight | |
? ctx.transform(0, -1, 1, 0, 0, img.height) | |
: ctx.transform(0, 1, -1, 0, img.height, 0) | |
ctx.drawImage(img, 0, 0) | |
const newImage = canvas.toDataURL('image/png') | |
props.onRotateImage(newImage) | |
} | |
img.src = src | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment