0 Пользователей и 1 Гость просматривают эту тему.
  • 2 Ответов
  • 1936 Просмотров
*

NlCK

  • Захожу иногда
  • 160
  • 1 / 0
Даже если пользователь грузит фото в 3Мб, чтобы при загрузке на сервер фото урезалось до размеров 200px в высоту.
Можно так сделать?
*

migus

  • Moderator
  • 1000
  • 144 / 0
  • OPEN THE BOX
Можно, но придется делать хак функции
Код: php-brief
public function uploadavatar()
в контроллере account.php

Кстати, начиная с Joomla!® 3.x.x появился новый метод
Код: php-brief
cropResize($width, $height, $createNew = true);
класса JImage, который как раз это и делает...

- удачи ;)
« Последнее редактирование: 14.05.2014, 20:21:22 от migus »
"The Lord Of A SandBox"
*

NlCK

  • Захожу иногда
  • 160
  • 1 / 0
нашел решение, думаю многим пригодится
меням строчку из controllers/account.php
эту
Код
if (!JFile::upload($file['tmp_name'], $filepath)) {
на эту
Код
if (!JFile::thumb($file['tmp_name'], $filepath,300)) {
а новую функцию добавляем в libraries/joomla/filesystem/file.php после функции upload
Код
function thumb($file, $save, $width, $height)
    {
        @unlink($save);
 
        if (!$infos = @getimagesize($file)) {
            return false;
        }
 
        $iWidth = $infos[0];
        $iHeight = $infos[1];
        
        //$iRatioW = $width / $iWidth;
        //$iRatioH = $height / $iHeight;
        
        //$iNewH = $height;
        
        if(!empty($height))
            $iNewH = $height;
        
        if(!empty($width))
            $iNewW = $width;
    
        if(empty($height))
            $iNewH = ($iHeight/$iWidth)*$iNewW;
        
        ///Condition if width blank then set autowidth... otherwise set passing width...
        if(empty($width))
            $iNewW = ($iWidth/$iHeight)*$iNewH;
 
        //Don't resize images which are smaller than thumbs
        if ($infos[0] < $width && $infos[1] < $height) {
            $iNewW = $infos[0];
            $iNewH = $infos[1];
        }
 
        if($infos[2] == 1) {
 
            $imgA = imagecreatefromgif($file);
            $imgB = imagecreate($iNewW,$iNewH);
            
            if(function_exists('imagecolorsforindex') && function_exists('imagecolortransparent')) {
                $transcolorindex = imagecolortransparent($imgA);
                    //transparent color exists
                    if($transcolorindex >= 0 ) {
                        $transcolor = imagecolorsforindex($imgA, $transcolorindex);
                        $transcolorindex = imagecolorallocate($imgB, $transcolor['red'], $transcolor['green'], $transcolor['blue']);
                        imagefill($imgB, 0, 0, $transcolorindex);
                        imagecolortransparent($imgB, $transcolorindex);
                    //fill white
                    } else {
                        $whitecolorindex = @imagecolorallocate($imgB, 255, 255, 255);
                        imagefill($imgB, 0, 0, $whitecolorindex);
                    }
            //fill white
            } else {
                $whitecolorindex = imagecolorallocate($imgB, 255, 255, 255);
                imagefill($imgB, 0, 0, $whitecolorindex);
            }
            imagecopyresampled($imgB, $imgA, 0, 0, 0, 0, $iNewW, $iNewH, $infos[0], $infos[1]);
            imagegif($imgB, $save);        
 
        } elseif($infos[2] == 2) {
 
            $imgA = imagecreatefromjpeg($file);
            $imgB = imagecreatetruecolor($iNewW,$iNewH);
            imagecopyresampled($imgB, $imgA, 0, 0, 0, 0, $iNewW, $iNewH, $infos[0], $infos[1]);
            imagejpeg($imgB, $save);
            
 
        } elseif($infos[2] == 3) {
            /*
            * Image is typ png
            */
            $imgA = imagecreatefrompng($file);
            $imgB = imagecreatetruecolor($iNewW, $iNewH);
            imagealphablending($imgB, false);
            imagecopyresampled($imgB, $imgA, 0, 0, 0, 0, $iNewW, $iNewH, $infos[0], $infos[1]);
            imagesavealpha($imgB, true);
            imagepng($imgB, $save);
            
        } else {
            return false;
        }
        return true;
    }
взял отсюда
http://chandreshmaheshwari.wordpress.com/2011/08/09/resize-image-function-in-joomla/
Чтобы оставить сообщение,
Вам необходимо Войти или Зарегистрироваться
 

Ошибка при загрузке авы

Автор Katya

Ответов: 3
Просмотров: 1307
Последний ответ 21.05.2015, 12:48:12
от migus
Как сделать правило "Загрузить аватар профиля"?

Автор Сergei

Ответов: 1
Просмотров: 1723
Последний ответ 12.05.2014, 15:40:43
от NlCK
Как сделать покупку баллов за рубли?

Автор Сergei

Ответов: 0
Просмотров: 1267
Последний ответ 16.01.2014, 23:31:25
от Сergei
Как сделать правило/плагин "Профиль заполнен"?

Автор Сergei

Ответов: 0
Просмотров: 1369
Последний ответ 14.09.2013, 10:16:57
от Сergei
AlphaUserPoints 1.8.3 можно ли баллы в правилах сделать рублями?

Автор iln11

Ответов: 1
Просмотров: 1781
Последний ответ 30.04.2013, 21:32:58
от Deamelfuse