1. Приветствуем Вас на неофициальном форуме технической поддержки XenForo на русском языке. XenForo - коммерческий форумный движок от бывших создателей vBulletin, написанный на PHP.

Обработка изображений (GD-библиотека) - создание квадратных thumbnail'ов

Тема в разделе "Основные вопросы по XenForo", создана пользователем 3dfx3dfk, 04.03.2013.

Загрузка
  1. 3dfx3dfk

    3dfx3dfk Read only

    Регистрация:
    08.02.13
    Сообщения:
    9
    Симпатии:
    1
    Версия XF:
    1.0.2
    Превью изображений в ксене не обрезается по высоте или ширине, а выводится с сохранением оригинальных пропорций. В этом и заключается большая для меня проблема, особенно когда загружаются изображения вертикальной и горизонтальной ориентации и выводятся в теме - это выглядит не очень красиво.
    Хочется чтобы превью изображений создавались с четкими пропорциями и там где надо урезались или увеличивались.
    Обработка изображений идет в файле /library/xenforo/image/gd.php
    Код :
    PHP:
        /**
        * Thumbnails the image.
        *
        * @see XenForo_Image_Abstract::thumbnail()
        */
        
    public function thumbnail($maxWidth$maxHeight 0)
        {
            if (
    $maxWidth 10)
            {
                
    $maxWidth 10;
            }
            if (
    $maxHeight 10)
            {
                
    $maxHeight $maxWidth;
            }
     
            if (
    $this->_width $maxWidth && $this->_height $maxHeight)
            {
                return 
    false;
            }
     
            
    $ratio $this->_width $this->_height;
     
            
    $maxRatio = ($maxWidth $maxHeight);
     
            if (
    $maxRatio $ratio)
            {
                
    $width max(1$maxHeight $ratio);
                
    $height $maxHeight;
            }
            else
            {
                
    $width $maxWidth;
                
    $height max(1$maxWidth $ratio);
            }
     
            
    $newImage imagecreatetruecolor($width$height);
            
    $this->_preallocateBackground($newImage);
     
            
    imagecopyresampled(
                
    $newImage$this->_image,
                
    0000,
                
    $width$height$this->_width$this->_height
            
    );
            
    $this->_setImage($newImage);
     
            return 
    true;
        }
     
    /**
    * Produces a thumbnail of the current image whose shorter side is the specified length
    *
    * @see XenForo_Image_Abstract::thumbnailFixedShorterSide
    */
    public function thumbnailFixedShorterSide($shortSideLength)
    {
    if (
    $shortSideLength 10)
    {
    $shortSideLength 10;
    }
     
    $ratio $this->_width $this->_height;
    if (
    $ratio 1// landscape
    {
    $width $shortSideLength $ratio;
    $height $shortSideLength;
    }
    else
    {
    $width $shortSideLength;
    $height max(1$shortSideLength $ratio);
    }
     
    $newImage imagecreatetruecolor($width$height);
    $this->_preallocateBackground($newImage);
     
    imagecopyresampled(
    $newImage$this->_image,
    0000,
    $width$height$this->_width$this->_height);
    $this->_setImage($newImage);
    }
     
    /**
    * Crops the image.
    *
    * @see XenForo_Image_Abstract::crop()
    */
    public function crop($x$y$width$height)
    {
    $newImage imagecreatetruecolor($width$height);
    $this->_preallocateBackground($newImage);
     
    imagecopyresampled(
    $newImage$this->_image,
    00$x$y,
    $width$height$width$height
    );
    $this->_setImage($newImage);
    }
    В пхп я не разбираюсь, может кто сделать правку чтобы превью выводились с заданными пропорциями?
     

Поделиться этой страницей