Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rotate an image in image source in html

Is there a way I could add in the source of my image codes that could rotate my image?

Something like this:

<img id="image_canv" src="/image.png" rotate="90"> 

I'm making my images dynamic, so I was wondering if I could append some extra code to rotate it if I want it to.

like image 488
marchemike Avatar asked Nov 19 '13 02:11

marchemike


People also ask

How do I rotate an image horizontally in HTML?

You may do a transform: rotate(180deg); for the horizontal+vertical flip.

How do I rotate an image 360 degrees in HTML?

Edit in JSFiddleClick – 360 degree image rotation is performed after mouse is clicked on the image and moved. MouseMove - 360 degree image rotation is performed when mouse is moved over the Image. Auto - 360 degree image rotation is performed automatically.

How do I rotate an image in Dreamweaver?

From the menu bar, select Modify > Transform > Numeric Transform. A new dialog box will open. From the dropdown box, select Rotate. In the center textbox, next to the angle icon , type the number of degrees to rotate the photo.


2 Answers

If your rotation angles are fairly uniform, you can use CSS:

<img id="image_canv" src="/image.png" class="rotate90"> 

CSS:

.rotate90 {     -webkit-transform: rotate(90deg);     -moz-transform: rotate(90deg);     -o-transform: rotate(90deg);     -ms-transform: rotate(90deg);     transform: rotate(90deg); } 

Otherwise, you can do this by setting a data attribute in your HTML, then using Javascript to add the necessary styling:

<img id="image_canv" src="/image.png" data-rotate="90"> 

Sample jQuery:

$('img').each(function() {     var deg = $(this).data('rotate') || 0;     var rotate = 'rotate(' + deg + 'deg)';     $(this).css({          '-webkit-transform': rotate,         '-moz-transform': rotate,         '-o-transform': rotate,         '-ms-transform': rotate,         'transform': rotate      }); }); 

Demo:

http://jsfiddle.net/verashn/6rRnd/5/

like image 136
VLS Avatar answered Sep 21 '22 09:09

VLS


You can do this:

<img src="your image" style="transform:rotate(90deg);"> 

it is much easier.

like image 32
user9770563 Avatar answered Sep 19 '22 09:09

user9770563