Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //код приводит изображение к максимально заданным размерам
- header('Content-Type: image/jpeg');
- $filename = 'imagev.jpg';
- $width = 300; //maximum values
- $height = 300;
- list($width_orig, $height_orig) = getimagesize($filename);// присваеваем значения переменным ширины и высоты оригинала
- if ($width_orig > $width) {
- $w_ratio = $width / $width_orig;
- $fin_hegight = $height_orig * $w_ratio;
- $fin_width = $width;
- } elseif ($height_orig > $height){
- $h_ratio = $height / $height_orig;
- $fin_width = $width_orig * $h_ratio;
- $fin_height = $height;
- }
- $image_p = imagecreatetruecolor($fin_width, $fin_hegight);
- $image = imagecreatefromjpeg($filename);
- imagecopyresampled($image_p, $image, 0, 0, 0, 0, $fin_width, $fin_hegight, $width_orig, $height_orig);
- imagejpeg($image_p, null, 100);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement