Skip to content

Instantly share code, notes, and snippets.

@vmoratog
Created November 29, 2019 03:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vmoratog/cb5f8972aca7f6a7fd7502aa1774c553 to your computer and use it in GitHub Desktop.
Save vmoratog/cb5f8972aca7f6a7fd7502aa1774c553 to your computer and use it in GitHub Desktop.
Rotate images in Canvas
const imageData = canvas.toDataURL()
const degrees = 90
const image = new Image();
image.onload = () => {
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.save();
ctx.translate(canvas.width / 2, canvas.height / 2);
ctx.rotate(degrees * Math.PI / 180);
ctx.drawImage(image, -image.width / 2, -image.width / 2);
ctx.restore();
// NEW IMAGE HERE!
// canvas.toDataURL()
};
image.src = imageData
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment