<!DOCTYPE html> <html> <body> <p>要使用的图像:</p> <img id="tulip" src="http://www.w3school.com.cn/i/eg_tulip.jpg" alt="The Tulip" /> <p>翻转</p> <canvas id="myCanvas" width="400" height="266" style="border:1px solid #d3d3d3;background:#ffffff;"> Your browser does not support the HTML5 canvas tag. </canvas> <script> var c=document.getElementById("myCanvas"); var ctx=c.getContext("2d"); var img=document.getElementById("tulip"); //垂直 ctx.translate(0, 300); ctx.scale(1, -1); ctx.drawImage(img,0,34); //水平 //ctx.translate(400, 0); //ctx.scale(-1, 1); //ctx.drawImage(img,0,0); </script> </body> </html>
https://blog.oldj.net/2011/02/09/flip-images-in-html5/