Забыли пароль?
Запросите новый здесь.

Автор темы: mpflash
ID темы: 2493
Информация:
Тема содержит 1 сообщения, была просмотрена 2056 раз.  Имеются прикрепленные файлы.
Просмотр темы
PHP-Fusion Russia » Веб-разработка » PHP
 Распечатать тему
Обрезка а не уменьшение в выгружаемых изображениях
mpflash
Добрый день, помогите перепилить функцию, может кто уже вносил подобные изменения, задача сделать так:

Текущий режим работы: вписыввание изображение в указанный прямоугольник аля 800х600, без изменения пропорций.
Нужный режим обрезка боковых или верхнижних полей для вписывания в такую же область аля 800х600.

Загрузить источник  GeSHi: PHP
  1. function createthumbnail($filetype, $origfile, $thumbfile, $new_w, $new_h) {
  2.  
  3. global $settings;
  4.  
  5. if ($filetype == 1) { $origimage = imagecreatefromgif($origfile); }
  6. elseif ($filetype == 2) { $origimage = imagecreatefromjpeg($origfile); }
  7. elseif ($filetype == 3) { $origimage = imagecreatefrompng($origfile); }
  8.  
  9. $old_x = imagesx($origimage);
  10. $old_y = imagesy($origimage);
  11.  
  12. $ratio_x = $old_x / $new_w;
  13. $ratio_y = $old_y / $new_h;
  14. if ($ratio_x > $ratio_y) {
  15. $thumb_w = round($old_x / $ratio_x);
  16. $thumb_h = round($old_y / $ratio_x);
  17. } else {
  18. $thumb_w = round($old_x / $ratio_y);
  19. $thumb_h = round($old_y / $ratio_y);
  20. };
  21.  
  22. if ($settings['thumb_compression'] == "gd1") {
  23. $thumbimage = imagecreate($thumb_w,$thumb_h);
  24. $result = imagecopyresized($thumbimage, $origimage, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
  25. } else {
  26. $thumbimage = imagecreatetruecolor($thumb_w,$thumb_h);
  27. if ($filetype == 3) {
  28. imagealphablending($thumbimage, false);
  29. imagesavealpha($thumbimage, true);
  30. }
  31. $result = imagecopyresampled($thumbimage, $origimage, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
  32. }
  33.  
  34. touch($thumbfile);
  35.  
  36. if ($filetype == 1) { imagegif($thumbimage, $thumbfile); }
  37. elseif ($filetype == 2) { imagejpeg($thumbimage, $thumbfile); }
  38. elseif ($filetype == 3) { imagepng($thumbimage, $thumbfile); }
  39.  
  40. imagedestroy($origimage);
  41. imagedestroy($thumbimage);
  42. }
Добавлено за 0.037 секунд, используя GeSHi 1.0.8.10



Да, замечания по поводу обрезки вертикальных фотографий почти в 2 раза я учитываю, и про панорамы помню.

--------------------------------------------------------------
ответ не получил..................

назвал другой функцией - createthumbcrop и обрабатываю ей только эскизы. Теперь пользовательская галлерея, доска объявлений, ну и основная галлерея может выглядеть одинаковыми эскизами,

Загрузить источник  GeSHi: PHP
  1. function createthumbcrop($filetype, $origfile, $thumbfile, $new_w, $new_h) {
  2.  
  3. global $settings;
  4.  
  5. if ($filetype == 1) { $origimage = imagecreatefromgif($origfile); }
  6. elseif ($filetype == 2) { $origimage = imagecreatefromjpeg($origfile); }
  7. elseif ($filetype == 3) { $origimage = imagecreatefrompng($origfile); }
  8.  
  9. $old_x = imagesx($origimage);
  10. $old_y = imagesy($origimage);
  11.  
  12. $ratio_x = $old_x / $new_w;
  13. $ratio_y = $old_y / $new_h;
  14. $crop_y = 0;
  15. $crop_x = 0;
  16.  
  17. if ($ratio_x < $ratio_y) {
  18. $thumb_w = round($old_x / $ratio_x);
  19. $thumb_h = round($old_y / $ratio_x);
  20. $crop_y = ($old_y - ($new_h * $ratio_x))/2;
  21. } else {
  22. $thumb_w = round($old_x / $ratio_y);
  23. $thumb_h = round($old_y / $ratio_y);
  24. $crop_x = ($old_x - ($new_w * $ratio_y))/2;
  25. }
  26.  
  27. if ($settings['thumb_compression'] == "gd1") {
  28. $thumbimage = imagecreate($new_w,$new_h);
  29. $result = imagecopyresized($thumbimage, $origimage, 0, 0, $crop_x, $crop_y, $thumb_w, $thumb_h, $old_x, $old_y);
  30. } else {
  31. $thumbimage = imagecreatetruecolor($new_w,$new_h);
  32. if ($filetype == 3) {
  33. imagealphablending($thumbimage, false);
  34. imagesavealpha($thumbimage, true);
  35. }
  36.  
  37. $result = imagecopyresampled($thumbimage, $origimage, 0, 0, $crop_x, $crop_y, $thumb_w, $thumb_h, $old_x, $old_y);
  38. }
  39.  
  40. touch($thumbfile);
  41.  
  42. if ($filetype == 1) { imagegif($thumbimage, $thumbfile); }
  43. elseif ($filetype == 2) { imagejpeg($thumbimage, $thumbfile); }
  44. elseif ($filetype == 3) { imagepng($thumbimage, $thumbfile); }
  45.  
  46. imagedestroy($origimage);
  47. imagedestroy($thumbimage);
  48. }
Добавлено за 0.022 секунд, используя GeSHi 1.0.8.10


Вложения не в тех масштабах отобразились, суть в том что остается только то, что вписывается в ваши размеры.
mpflash присоединено следующее:изображения:
1-1429913165a.jpg 1-1429913054d.jpg crop-y.jpg crop-x.jpg

Изменил(а) mpflash, 24.04.2015 22:28
 

Поделиться этой темой
Социальные закладки: Vkontakte Odnoklassniki Mail.ru Facebook Google Tweet This
URL:
BBcode:
HTML:

Перейти на форум:
Топ 5 пользователей форума
Zaxap Zaxap (1,090)   Vova Vova (877)   Pisatel Pisatel (678)   util util (666)   SchreiBear SchreiBear (625)