Advertisement
fahmihilmansyah

Caman Cropper

Dec 7th, 2016
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var Cropper = window.Cropper;
  2.     var URL = window.URL || window.webkitURL;
  3.     var image = $("#gambars")[0];
  4.     var options = {
  5.         aspectRatio: 16 / 9,
  6.         preview: '.img-preview',
  7.     }
  8.     var cropper = new Cropper(image, options);
  9.     var originalImageURL = image.src;
  10.     var uploadedImageURL;
  11.  
  12.     // Import image
  13.     var inputImage = $('#inputImage')[0];
  14.     // var inputImage = document.getElementById('inputImage');
  15.  
  16.     if (URL) {
  17.     inputImage.onchange = function () {
  18.         $(".gambar").show();
  19.       var files = this.files;
  20.       var file;
  21.  
  22.       if (cropper && files && files.length) {
  23.         file = files[0];
  24.  
  25.         if (/^image\/\w+/.test(file.type)) {
  26.           image.src = uploadedImageURL = URL.createObjectURL(file);
  27.           cropper.destroy();
  28.           cropper = new Cropper(image, options);
  29.           inputImage.value = null;
  30.         } else {
  31.           window.alert('Please choose an image file.');
  32.         }
  33.       }
  34.     };
  35.     } else {
  36.     inputImage.attr('disabled',true);
  37.     inputImage.parentNode.className += ' disabled';
  38.     }
  39. $("#grayscale").on('click',function(){  
  40.           Caman('#gambars', function () {
  41.             this.brightness(10);
  42.             this.render();
  43.           });
  44.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement