Skip to content

Instantly share code, notes, and snippets.

@yuritoledo
Created August 13, 2019 20:12
Show Gist options
  • Save yuritoledo/77b2f8f9e8e4b288609b12d47e720cf3 to your computer and use it in GitHub Desktop.
Save yuritoledo/77b2f8f9e8e4b288609b12d47e720cf3 to your computer and use it in GitHub Desktop.
Rotate image and get new base64
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