Guest User

Untitled

a guest
May 27th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.48 KB | None | 0 0
  1. <?php
  2. function Resize_Image($save,$file,$t_w,$t_h,$s_path,$o_path) {
  3.     $s_path = trim($s_path);
  4.     $o_path = trim($o_path);
  5.     $save = $s_path . $save;
  6.     $file = $o_path . $file;
  7.     $ext = strtolower(end(explode('.',$save)));
  8.     list($width, $height) = getimagesize($file) ;  
  9.     if(($width>$t_w) OR ($height>$t_h)) {
  10.         $r1 = $t_w/$width;
  11.         $r2 = $t_h/$height;
  12.         if($r1<$r2) {
  13.           $size = $t_w/$width;
  14.         }else{
  15.           $size = $t_h/$height;
  16.         }
  17.     }else{
  18.         $size=1;
  19.     }
  20.     $modwidth = $width * $size;  
  21.     $modheight = $height * $size;  
  22.     $tn = imagecreatetruecolor($modwidth, $modheight) ;  
  23.     switch ($ext) {
  24.         case 'jpg':
  25.         case 'jpeg':
  26.                     $image = imagecreatefromjpeg($file) ;  
  27.         break;
  28.         case 'gif':
  29.                     $image = imagecreatefromgif($file) ;  
  30.         break;
  31.         case 'png':
  32.                     $image = imagecreatefrompng($file) ;  
  33.         break;
  34.     }
  35.     imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;  
  36.     imagejpeg($tn, $save, 100) ;  
  37.     return;
  38. }
  39. //just the resize; first one resizes properly, second one resizes sometimes, but dark images tend to turn fully black
  40. Resize_Image($fullname,$fullname,600,600,'fotos/'.$urlnaam.'/large/','fotos/'.$urlnaam.'/large/');
  41.                 Resize_Image($fullname,$fullname,120,120,'fotos/'.$urlnaam.'/thumbs/','fotos/'.$urlnaam.'/large/');
  42. ?>
Add Comment
Please, Sign In to add comment