Задача: Масштабирование, пропорциональное изменение размеров картинки
Исходник: Вариант №4 из комментов к документации php, язык: php [code #103, hits: 7920]
автор: - [добавлен: 26.03.2006]
  1. $picture = ""; # picture fileNAME here. not address
  2. $max=150; # maximum size of 1 side of the picture.
  3. /*
  4. here you can insert any specific "if-else",
  5. or "switch" type of detector of what type of picture this is.
  6. in this example i'll use standard JPG
  7. */
  8. $src_img=ImagecreateFromJpeg($picture);
  9. $oh = imagesy($src_img); # original height
  10. $ow = imagesx($src_img); # original width
  11. $new_h = $oh;
  12. $new_w = $ow;
  13. if($oh > $max || $ow > $max){
  14. $r = $oh/$ow;
  15. $new_h = ($oh > $ow) ? $max : $max*$r;
  16. $new_w = $new_h/$r;
  17. }
  18. // note TrueColor does 256 and not.. 8
  19. $dst_img = ImageCreateTrueColor($new_w,$new_h);
  20. ImageCopyResized($dst_img, $src_img, 0,0,0,0, $new_w, $new_h, ImageSX($src_img), ImageSY($src_img));
  21. ImageJpeg($dst_img, "th_$picture");
backglancer at hotmail (14-Dec-2004 03:10):

"Neat script to create a thumbnails no larger than 150 (or user-specific) height AND width."

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

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

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