Advertisement
arijulianto

Upload Crop Image dengan imgareaselect (2)

Jan 22nd, 2014
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.78 KB | None | 0 0
  1. <link rel="stylesheet" type="text/css" href="css/imgareaselect-default.css" />
  2. <script type="text/javascript" src="scripts/jquery.min.js"></script>
  3. <script type="text/javascript" src="scripts/jquery.imgareaselect.pack.js"></script>
  4. <script type="text/javascript">
  5. $(function () {
  6. $('#crop').imgAreaSelect({
  7.   aspectRatio: '2:1',
  8.   handles: true,
  9.   onSelectChange: function (img, selection) {
  10.     $('input[name="x1"]').val(selection.x1);
  11.     $('input[name="y1"]').val(selection.y1);
  12.     $('input[name="x2"]').val(selection.x2);
  13.     $('input[name="y2"]').val(selection.y2);  
  14.     $('input[name="w"]').val(selection.width);  
  15.     $('input[name="h"]').val(selection.height);            
  16.   }
  17. });
  18. });
  19. function cekCrop(){
  20.     if (parseInt($('#w').val())) return true;
  21.     return false;
  22. }
  23. </script>
  24.  
  25. <?php
  26. if($_SERVER['REQUEST_METHOD'] == 'POST'){
  27.   $targ_w = 620;
  28.   $targ_h = 310;
  29.   $jpeg_quality = 90;
  30.   $src = '12.jpg';
  31.   $img_r = imagecreatefromjpeg($src);
  32.   $dst_r = ImageCreateTrueColor( $targ_w, $targ_h );
  33.   imagecopyresampled($dst_r,$img_r,0,0,$_POST['x1'],$_POST['y1'],$targ_w,$targ_h,$_POST['w'],$_POST['h']);
  34.   imagejpeg($dst_r,'test2.jpg',$jpeg_quality);
  35. }
  36. ?>
  37.  
  38. <script type="text/javascript" src="../scripts/plugins-jquery-cropimg.min.js"></script>
  39. <script>
  40. $(function(){
  41. function pick(input) {
  42.     if(input.files && input.files[0] && input.files[0].type.match('image*')){
  43.         var reader = new FileReader();
  44.     var n = String(input.name).replace('img','');
  45.         reader.onload = function (e) {
  46.         $('#imgPreview').prop('src', e.target.result).show();
  47.         }
  48.         reader.readAsDataURL(input.files[0]);
  49.     }
  50.     if (!String(input.files[0].name).match(/(?:gif|jpg|png|bmp)$/)) {
  51.         alert('Harap pilih file gambar saja dengan format JPG, PNG, atau GIF');
  52.         input.value='';
  53.     }
  54. }
  55. $('.i-file').on('change',function(){
  56.     pick(this);
  57. })
  58.  
  59. $('#imgPreview').imgAreaSelect({
  60.     aspectRatio: '2:1',
  61.     handles: true,
  62.     onSelectChange: function (img, selection) {
  63.         $('input[name="x1"]').val(selection.x1);
  64.         $('input[name="y1"]').val(selection.y1);
  65.         $('input[name="x2"]').val(selection.x2);
  66.         $('input[name="y2"]').val(selection.y2);
  67.         $('input[name="w"]').val(selection.width);
  68.         $('input[name="h"]').val(selection.height);
  69.     }
  70. });
  71. })
  72. </script>
  73. <form action="" method="post" enctype="multipart/form-data">
  74. <p><img id="imgPreview" style="display:none" width=620 align="middle" /><input type="file" class="i-file" name="img" /></p>
  75. <p><input type="text" name="x1" value="" /><input type="text" name="y1" value="" /><input type="text" name="x2" value="" /><input type="text" name="y2" value="" /><input type="text" name="w" id="w" value="" /><input type="text" name="h" value="" /></p>
  76. <p><input type="submit" name="simpan" /></p>
  77. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement