Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rotate Image in JavaScript with new Image()

I tried to rotate an image in javascript using the new Image() I tried with this:

this.gunner = new Image()
this.gunner.src = *url*
this.gunner.style.WebkitTransform = "rotate(20deg)"

but the image still was like normal.

How can I do this?

like image 229
SIMONE ESPOSITO Avatar asked Oct 17 '22 15:10

SIMONE ESPOSITO


1 Answers

Try this:

var image = new Image();
image.src = 'http://placehold.it/350x150';
document.body.append(image);
image.style.transform = "rotate(90deg)";
like image 185
meltuhamy Avatar answered Oct 21 '22 00:10

meltuhamy