How to rotate the image in Canvas?

I know that you can turn the canvas, but to create a new canvas for each picture is not an option, because there are a lot of pictures.

    2 answers 2

    How to rotate only one image on canvas

    Here I answered in detail. If in brief, then you need to do the context beforehand, before doing the transformation, twisting and similar manipulations with the canvas.

    ctx.save(); 

    After we draw the necessary fragment we return the old settings

     ctx.restore(); 
    • it is not necessary to save then restore the current context - if you implement all the basic affine transformations on the plane into manual then you can transform everything that is drawn on the canvas without touching the coordinate system in principle. - ampawd