Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $size = getimagesize(Yii::$app->basePath.'/web/im.jpg');
- if($size[0] > 600 || $size[1] > 400)
- {
- /*
- * PHP GD
- * resize an image using GD library
- */
- // File and new size
- //the original image has 800x600
- $filename = Yii::$app->basePath.'/web/im.jpg';
- //the resize will be a percent of the original size
- $percent = 0.2;
- // Content type
- header('Content-Type: image/jpeg');
- // Get new sizes
- list($width, $height) = getimagesize($filename);
- $newwidth = $width * $percent;
- $newheight = $height * $percent;
- // Load
- $thumb = imagecreatetruecolor(100, 100);
- $source = imagecreatefromjpeg($filename);
- // Resize
- imagecopyresized($thumb, $source, 0, 0, 0, 0, 100, 100, $width, $height);
- // Output and free memory
- //the resized image will be 400x300
- imagejpeg($thumb);
- imagedestroy($thumb);
- }
Advertisement
Add Comment
Please, Sign In to add comment