Last active
June 5, 2018 21:52
-
-
Save anacampesan/8866c633210b3517edb87209411f6690 to your computer and use it in GitHub Desktop.
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
let img = new Image(); | |
img.onload = function() { | |
let canvas = document.createElement('canvas'); | |
let ctx = canvas.getContext('2d'); | |
canvas.width = img.width; | |
canvas.height = img.height; | |
canvas.width = img.height; | |
canvas.height = img.width; | |
ctx.translate(img.height, 0); | |
ctx.rotate(90 * Math.PI / 180); | |
ctx.drawImage(this, 0, 0); | |
document.body.appendChild(canvas); | |
} | |
img.src = 'https://comotion.uw.edu/wp-content/uploads/2017/06/image.jpg'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
canvas width becomes img height and vice versa. at 90 degrees, the object will fall off the canvas, so we need to adjust the x (horizontal) axis of where the canvas should start. the context can be saved and then restored in case any other operation needs to be made afterwards.