Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.41 KB | None | 0 0
  1. <?php
  2.    if(isset($_POST['imagebase64'])){
  3.        $data = $_POST['imagebase64'];
  4.  
  5.        list($type, $data) = explode(';', $data);
  6.        list(, $data)      = explode(',', $data);
  7.        $data = base64_decode($data);
  8.  
  9.        file_put_contents('image64.png', $data);
  10.    }
  11. ?>
  12.  
  13.   <!DOCTYPE html>
  14.   <html>
  15.  
  16.   <head>
  17.     <meta charset="utf-8">
  18.     <title>Test crop</title>
  19.     <link href="/static/croppie.css" rel="stylesheet" type="text/css">
  20.     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
  21.     <script type="text/javascript" src="/static/croppie.min.js"></script>
  22.     <script type="text/javascript">
  23.       $( document ).ready(function() {
  24.           var $uploadCrop;
  25.      
  26.           function readFile(input) {
  27.               if (input.files && input.files[0]) {
  28.                  var reader = new FileReader();          
  29.                   reader.onload = function (e) {
  30.                       $uploadCrop.croppie('bind', {
  31.                           url: e.target.result
  32.                       });
  33.                       $('.upload-demo').addClass('ready');
  34.                   }          
  35.                   reader.readAsDataURL(input.files[0]);
  36.               }
  37.           }
  38.      
  39.           $uploadCrop = $('#upload-demo').croppie({
  40.               viewport: {
  41.                   width: 200,
  42.                   height: 200,
  43.                   type: 'square'
  44.               },
  45.               boundary: {
  46.                   width: 300,
  47.                   height: 300
  48.               }
  49.           });
  50.      
  51.           $('#upload').on('change', function () { readFile(this); });
  52.           $('.upload-result').on('click', function (ev) {
  53.               $uploadCrop.croppie('result', {
  54.                   type: 'canvas',
  55.                   size: 'original'
  56.               }).then(function (resp) {
  57.                   $('#imagebase64').val(resp);
  58.                   $('#form').submit();
  59.               });
  60.           });
  61.      
  62.       });
  63.     </script>
  64.   </head>
  65.  
  66.   <body>
  67.     <form action="testth.php" id="form" method="post">
  68.       <input type="file" id="upload" value="Choose a file">
  69.       <div id="upload-demo"></div>
  70.       <input type="hidden" id="imagebase64" name="imagebase64">
  71.       <!--<a href="#" class="upload-result">Send</a> Working with this...-->
  72.       <input name="submit" type="submit" value="Crop It !" class="form_submit" />
  73.     </form>
  74.   </body>
  75.  
  76.   </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement