Vladimir3261

Untitled

Nov 24th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.96 KB | None | 0 0
  1.         $size = getimagesize(Yii::$app->basePath.'/web/im.jpg');
  2.         if($size[0] > 600 || $size[1] > 400)
  3.         {
  4.  /*
  5.   * PHP GD
  6.   * resize an image using GD library
  7.   */
  8.  
  9. // File and new size
  10. //the original image has 800x600
  11.             $filename = Yii::$app->basePath.'/web/im.jpg';
  12. //the resize will be a percent of the original size
  13.             $percent = 0.2;
  14.  
  15. // Content type
  16.             header('Content-Type: image/jpeg');
  17.  
  18. // Get new sizes
  19.             list($width, $height) = getimagesize($filename);
  20.             $newwidth = $width * $percent;
  21.             $newheight = $height * $percent;
  22.  
  23. // Load
  24.             $thumb = imagecreatetruecolor(100, 100);
  25.             $source = imagecreatefromjpeg($filename);
  26.  
  27. // Resize
  28.             imagecopyresized($thumb, $source, 0, 0, 0, 0, 100, 100, $width, $height);
  29.  
  30. // Output and free memory
  31. //the resized image will be 400x300
  32.             imagejpeg($thumb);
  33.             imagedestroy($thumb);
  34.         }
Advertisement
Add Comment
Please, Sign In to add comment