Advertisement
Guest User

resize

a guest
Nov 5th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.09 KB | None | 0 0
  1. public function resizeImage($pic_type, $sourcePath, $destPath, $maxWidth, $maxHeight)
  2.     {
  3.  
  4.         switch ($pic_type) {
  5.             case 'png':
  6.                 $size = getimagesize($sourcePath);
  7.                 if ($size[1] / $size[0] > $maxHeight / $maxWidth) {
  8.                     $newHeight = $maxHeight;
  9.                     $newWidth = ceil($size[0] / $size[1] * $newHeight);
  10.                 } else {
  11.                     $newWidth = $maxWidth;
  12.                     $newHeight = ceil($size[1] / $size[0] * $newWidth);
  13.                 }
  14.                 $image = imagecreatefrompng($sourcePath);
  15.                 $newImage = imagecreatetruecolor($newWidth, $newHeight);
  16.                 imagecopyresampled($newImage, $image, 0, 0, 0, 0, $newWidth, $newHeight, $size[0], $size[1]);
  17.                 imagepng($newImage, $destPath);
  18.                 imagedestroy($image);
  19.                 imagedestroy($newImage);
  20.                 break;
  21.        }
  22. }
  23.  
  24. // Verkleinern für die Vorschau
  25. $this->resizeImage($ava_type, $upload_direction, $ava_tpath . 'thumb_' . $ava_fname . '.' . $ava_type, 500, 500);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement