JSFiddle - React, Tailwind, and code Playground

by Vijay Gujar

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/4.0.0-beta.5/fabric.js"></script>
<canvas id="canvas" width="500" height="500"></canvas>
<button id='btnRotate' onclick="changeRotation()" >
Rotate
</button>

CSS

#canvas {
    box-shadow: 0 0 5px 1px black;
}

JavaScript

var imgURL = 'http://i.imgur.com/8rmMZI3.jpg';

var canvas = new fabric.Canvas('canvas');
var cnvWidth = 200;
var cnvHeight = 200;
var angle = 0;
var _rotateScale = 0;
var _straightenValue = 0;

var clipPath = new fabric.Rect({ top: 10, left: 10, width: 480, height: 480, absolutePositioned: true});
var innerClipPath = new fabric.Rect({ top: 0, left: 0, width: 500, height: 500 ,absolutePositioned: true});
clipPath.clipPath = innerClipPath;
//canvas.add(clipPath);
/* var innerClipPath = new fabric.Rect({ top: -90, left: -90 });
clipPath.clipPath = innerClipPath; */
 /*  var group = new fabric.Group([
    new fabric.Rect({ width: 100, height: 100, fill: 'red' }),
    new fabric.Rect({ width: 100, height: 100, fill: 'yellow', left: 100 }),
    new fabric.Rect({ width: 100, height: 100, fill: 'blue', top: 100 }),
    new fabric.Rect({ width: 100, height: 100, fill: 'green', left: 100, top: 100 })
  ]); */
  //group.clipPath = clipPath;
  //canvas.add(group);
  
/* function changeRotation() {
if (angle === 45){
_rotateScale = 0;
angle = -5
} 
angle += 5;

var e = angle;
var img = canvas.getActiveObject();
 var t = {
                        x: img.width / 2,
                        y: img.height / 2
                    },
                    n = convertPointByAngle({
                        x: 0,
                        y: 0
                    }, t, Math.abs(e));
                t.x < t.y ? _rotateScale = 1 - n.x / t.x : _rotateScale = 1 + n.y / t.y,_straightenValue = e
   var img = canvas.getActiveObject();
      var scaleX = 0.5;//cnvWidth / img.width;
       var scaleY = 0.5;//cnvHeight / img.height;
       console.log(scaleX, scaleY);
       img.set('angle',10);
       img.scale(scaleX, scaleY);
       img.set('left', -10);
       img.set('top', -60);
       var width1 = img.width * img.scaleX;
       var height1 = img.height * img.scaleY;
       
       //img.scale(_rotateScale).setCoords();
       img.set('angle',angle);
       var width2 = img.width *...