This works vertically but I am trying to rotate horizontally by clicking on the image. Can not figure this out! Or there might be an easier way of doing this as well.
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Flip Image</title>
<style>
canvas{border:1px solid #333}
img{display:none;}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"> </script>
<script type="text/javascript">
$(window).load(function(){
var immagine = $('img')[0]
alt=immagine.height
lar=immagine.width
$('<canvas width="'+lar+'" height="'+alt+'"></canvas>').appendTo('body')
var ca=$('canvas').get(0)
ctx=ca.getContext('2d')
ctx.drawImage(immagine, 0, 0);
$('canvas').click(function(){
ctx.translate(lar-1, alt-1);
ctx.rotate(Math.PI);
ctx.drawImage(immagine, 0, 0, lar, alt);
})
})
</script>
</head>
<body>
<!-- onclick rotate image horizontally-->
<img src="myimage.jpg">
<br><Br>
</body>
</html>
Thanks!