Advertisement
GWibisono

resize gambar jadi 600x600

Dec 5th, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.54 KB | None | 0 0
  1. <?php
  2. if($_FILES)
  3. {
  4.     //echo '<pre>';print_r($_FILES);
  5.     /*
  6.     Array
  7. (
  8.     [files] => Array
  9.         (
  10.             [name] => earth_and_moon-1280x800.jpg
  11.             [type] => image/jpeg
  12.             [tmp_name] => C:\xampp\tmp\php5E88.tmp
  13.             [error] => 0
  14.             [size] => 134688
  15.         )
  16.  
  17. )
  18.     */
  19.     $filename0=$_FILES['files']['name'];
  20.     copy($_FILES['files']['tmp_name'],'1.tmp');
  21.  
  22.  
  23. // Content type
  24.     $filename="1.tmp";
  25.     $max=580;
  26.  
  27. // Get new dimensions
  28.     list($width, $height) = getimagesize($filename);
  29.    
  30.     if($width>$height)
  31.     {
  32.         $persen=$width/$max;
  33.        
  34.     }else{
  35.         $persen=$height/$max;
  36.     }
  37.    
  38.     $width1=$width/$persen;
  39.     $height1=$height/$persen;
  40.    
  41.     $x0=(600-$width1)/2;
  42.     $y0=(600-$height1)/2;
  43.     //die("$x0, $y0, 0, 0, $width1, $height1, $width, $height);");
  44.     $new_width = 600;
  45.     $new_height = 600;
  46.  
  47.     // Resample
  48.     $image_p = imagecreatetruecolor($new_width, $new_height);
  49.     $white = imagecolorallocate($image_p, 255, 255, 255);
  50.     imagefill($image_p, 0, 0, $white);
  51.     $image = imagecreatefromjpeg($filename);
  52.     imagecopyresampled($image_p, $image,
  53.     $x0, $y0, 0, 0,
  54.     $width1, $height1, $width, $height);
  55.  
  56. // Output
  57.     header('Content-Type: image/jpeg');
  58.     header('Content-Disposition: attachment; filename="'.$filename0.'"');
  59.     imagejpeg($image_p, null, 100);
  60.     die();
  61. }
  62.  
  63. ?><!DOCTYPE html>
  64. <html>
  65. <head>
  66.     <title></title>
  67. <? /*    <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
  68.  
  69.     <script src="../js/jquery-1.8.2.js"></script>
  70.     <script src="../js/kendo.all.js"></script>
  71.     <link href="styles/kendo.common.css" rel="stylesheet" />
  72.     <link href="styles/kendo.default.css" rel="stylesheet" />
  73. */
  74. ?></head>
  75. <body>
  76.     <div class='myform' >
  77.     <form enctype='multipart/form-data'  method="post" >
  78.     Masukkan File
  79.     <input name="files" id="myfiles" type="file" />
  80.                     <p>
  81.                         <input type="submit" value="Perbesar Gambar" class="k-button" />
  82.     </form>
  83.     </div>
  84.     <!--
  85.         <div id="example" class="k-content">
  86.            
  87.            
  88.             <form method="post" action="" style="width:45%">
  89.                 <div>
  90.                     <input name="files" id="files" type="file" />
  91.                     <p>
  92.                         <input type="submit" value="Submit" class="k-button" />
  93.                     </p>
  94.                 </div>
  95.             </form>
  96.             <script>
  97.                 $(document).ready(function() {
  98.                     $("#files").kendoUpload();
  99.                 });
  100.             </script>
  101.         </div>
  102. -->
  103.  
  104. </body>
  105. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement