Advertisement
GWibisono

crop (rahasia lho)

Nov 27th, 2014
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.34 KB | None | 0 0
  1. <?php
  2. if(isset($_POST['size'])){
  3.     copy($_FILES['logo']['tmp_name'], '002.jpg');
  4.     $s='<img src="002.jpg" /><br/><img src="002Resize.php?x='.$_POST['target']['x'].'&y='.$_POST['target']['y'].'">';
  5.  
  6.  
  7. die($s);
  8. }
  9.  
  10. if(isset($_GET['x'])){
  11.    
  12.     $img=getimagesize('002.jpg');
  13.     $x1=$img[0]; $y1=$img[1];
  14.     $x2=$_GET['x'];$y2=$_GET['y'];
  15.     $c=array(1, $y2/$x2);
  16.     $x3=$x1;
  17.     $y3=round($x1*$c[1]);
  18.    
  19.     $x4=round($y1*$c[0] / $c[1]);
  20.     $y4=$y1;
  21.    
  22.     if($x3<=$x1 && $y3 <= $y1){
  23.       $x0=0;
  24.       $y0=round(($y1-$y3 )/2);
  25.       $wX=$x3; $wY=$y3;
  26.     }  
  27.      
  28.     if($x4<=$x1 && $y4 <= $y1){
  29.       $x0=round(($x1-$x4 )/2);
  30.       $y0=0;
  31.       $wX=$x4; $wY=$y4;
  32.     }
  33.     //die ("   0,0, $x0,$y0, $x2,$y2, $wX,$wY ");
  34.     $im = imagecreatetruecolor($x2, $y2);
  35.     $im0 = imagecreatefromjpeg("002.jpg");
  36.     //$wX=$x2; $wY=$y2;
  37.     //$x0=($x1-$x2) /2 ; $y0=($y1-$y2) / 2;
  38.    
  39.     header('Content-type: image/jpeg');
  40.     imagecopyresized ( $im, $im0, 0,0, $x0,$y0, $x2,$y2, $wX,$wY);
  41.  
  42.     imagejpeg($im);
  43.  
  44.     die();
  45. }
  46.  
  47. ?>
  48. <form id='gbr' method="post" enctype="multipart/form-data">
  49. <input name='size' value='1' type='hidden' />
  50. <!-- size asal X <input name='source[x]' /> Y <input name='source[y]' />-->
  51. upload : <input type=file name='logo' />
  52. <br/>
  53. size tujuan X <input name='target[x]' value='50' /> <br/>Y <input name='target[y]' value='50' /><br/>
  54. <button id='generate'>Cari</button>
  55. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement