Advertisement
Guest User

Untitled

a guest
Jul 26th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. (function () {
  2.  
  3.  
  4. //getting ratio
  5. function getImageRatio(sourceCanvas) {
  6. var canvas = document.createElement('canvas');
  7. var context = canvas.getContext('2d');
  8. var width = sourceCanvas.width;
  9. var height = sourceCanvas.height;
  10.  
  11.  
  12.  
  13. canvas.width = width;
  14. canvas.height = height;
  15.  
  16.  
  17. context.beginPath();
  18. context.arc(width / 2, height / 2, Math.min(width, height) / 2, 0, 2 * Math.PI);
  19. context.strokeStyle = 'rgba(0,0,0,0)';
  20. context.stroke();
  21. context.clip();
  22. context.drawImage(sourceCanvas, 0, 0, width, height);
  23.  
  24. return canvas;
  25. }
  26.  
  27.  
  28.  
  29.  
  30. window.addEventListener('DOMContentLoaded', function () {
  31. var image = document.getElementById('image');
  32. var button = document.getElementById('button');
  33. var result = document.getElementById('result');
  34. var croppable = false;
  35. var cropper = new Cropper(image, {
  36. aspectRatio: 1,
  37. viewMode: 1,
  38. built: function () {
  39. croppable = true;
  40. }
  41. });
  42.  
  43. button.onclick = function () {
  44. var croppedCanvas;
  45. var roundedCanvas;
  46. var roundedImage;
  47.  
  48. if (!croppable) {
  49. return;
  50. }
  51.  
  52. // Crop
  53. croppedCanvas = cropper.getCroppedCanvas();
  54.  
  55.  
  56. console.log(getImageRatio(croppedCanvas));
  57.  
  58. };
  59.  
  60. });
  61.  
  62. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement