Advertisement
Guest User

Untitled

a guest
Apr 29th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. <?php
  2.  
  3. //код приводит изображение к максимально заданным размерам
  4.  
  5. header('Content-Type: image/jpeg');
  6. $filename = 'imagev.jpg';
  7. $width = 300; //maximum values
  8. $height = 300;
  9.  
  10. list($width_orig, $height_orig) = getimagesize($filename);// присваеваем значения переменным ширины и высоты оригинала
  11.  
  12. if ($width_orig > $width) {
  13. $w_ratio = $width / $width_orig;
  14. $fin_hegight = $height_orig * $w_ratio;
  15. $fin_width = $width;
  16. } elseif ($height_orig > $height){
  17. $h_ratio = $height / $height_orig;
  18. $fin_width = $width_orig * $h_ratio;
  19. $fin_height = $height;
  20. }
  21.  
  22. $image_p = imagecreatetruecolor($fin_width, $fin_hegight);
  23. $image = imagecreatefromjpeg($filename);
  24.  
  25. imagecopyresampled($image_p, $image, 0, 0, 0, 0, $fin_width, $fin_hegight, $width_orig, $height_orig);
  26.  
  27. imagejpeg($image_p, null, 100);
  28. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement