arijulianto

Upload Crop Image dengan imgareaselect

Jan 22nd, 2014
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.63 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. <p style="text-align: center;">
  26. <img id="crop" src="12.jpg" width=620 />
  27. </p>
  28. <?php
  29. if($_SERVER['REQUEST_METHOD'] == 'POST'){
  30.   $targ_w = 620;
  31.   $targ_h = 310;
  32.   $jpeg_quality = 90;
  33.   $src = '12.jpg';
  34.   $img_r = imagecreatefromjpeg($src);
  35.   $dst_r = ImageCreateTrueColor( $targ_w, $targ_h );
  36.   imagecopyresampled($dst_r,$img_r,0,0,$_POST['x2'],$_POST['y2'],$targ_w,$targ_h,$_POST['w'],$_POST['h']);
  37.   imagejpeg($dst_r,'test2.jpg',$jpeg_quality);
  38. }
  39. ?>
  40.  
  41. <form action="" method="post" onsubmit="return cekCrop();">
  42.   <input type="text" name="x1" value="" />
  43.   <input type="text" name="y1" value="" />
  44.   <input type="text" name="x2" value="" />
  45.   <input type="text" name="y2" value="" />
  46.   <input type="text" name="w" id="w" value="" />
  47.   <input type="text" name="h" value="" />
  48.   <input type="submit" name="submit" value="Submit" />
  49. </form>
Advertisement
Add Comment
Please, Sign In to add comment