Задача: Масштабирование, пропорциональное изменение размеров картинки
Исходник: Вариант №3 из комментов к документации php, язык: php [code #102, hits: 11316]
автор: - [добавлен: 26.03.2006]
  1. header('Content-type: image/jpeg');
  2. //$myimage = resizeImage('filename', 'newwidthmax', 'newheightmax');
  3. $myimage = resizeImage('test.jpg', '150', '120');
  4. print $myimage;
  5. function resizeImage($filename, $newwidth, $newheight){
  6. list($width, $height) = getimagesize($filename);
  7. if($width > $height && $newheight < $height){
  8. $newheight = $height / ($width / $newwidth);
  9. } else if ($width < $height && $newwidth < $width) {
  10. $newwidth = $width / ($height / $newheight);
  11. } else {
  12. $newwidth = $width;
  13. $newheight = $height;
  14. }
  15. $thumb = imagecreatetruecolor($newwidth, $newheight);
  16. $source = imagecreatefromjpeg($filename);
  17. imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
  18. return imagejpeg($thumb);
  19. }
smelban at smwebdesigns dot com (15-Feb-2005 04:37):

"Resize image proportionaly where you give a max width or max height"

http://www.php.net/imagecopyresized/

Тестировалось на: Apache 1.3.33, PHP 5.0

+добавить реализацию