Skip to content

Instantly share code, notes, and snippets.

@jorwan
Last active September 11, 2015 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorwan/1a736ff5bb037d463222 to your computer and use it in GitHub Desktop.
Save jorwan/1a736ff5bb037d463222 to your computer and use it in GitHub Desktop.
My Cunstom Jquery Plugings

Custom Jquery Plugin


Rotate Canvas Image from the center registration poing using degree
      /**
      *  Rotate Image in Canvas
      *  @params degree : degree to rotate
      */
      $.fn.rotateCanvasImageFromCenter = function(degree){
        this.each(function(){
          // canvas
          var canvas = this;
          // canvas context
          var context = canvas.getContext('2d');
          // Move registration point to the center of the canvas
          context.translate(440/2, 310/2);
          // Rotate 1 degree
          context.rotate(degree*Math.PI/180);
          // Move registration point back to the top left corner of canvas
          context.translate(-440/2, -310/2);
        });
      }
      
      // Using the plugin
      $('#canvas1').rotateCanvasImageFromCenter(90);
      $('.canvas2').rotateCanvasImageFromCenter(40);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment