Как ускорить выполнение Выполнение GM

181
14 декабря 2017, 00:12

Есть класс который служит для приведения фотографий к определенному стандарту 1024 х 756. ДЛя этого я использую GM.

Вопрос так ли я вызываю GM и как можно ускорить выполнение скрипта?

class CoreImgFiles {
private $files=[];
public $AllWaySavefiles=[];
public function __construct($allfiles)
{
   self::rewriteArray($allfiles);
   self::saveEvent();
}
private function rewriteArray($allfiles){
    $files = [];
    $file_count = count($allfiles['name'])-1;
    for($i=$file_count;$i>=0;$i--)
    {
        $files[] = $allfiles['tmp_name'][$i];
        unset($allfiles['name'][$i]);
        unset($allfiles['type'][$i]);
        unset($allfiles['tmp_name'][$i]);
        unset($allfiles['error'][$i]);
        unset($allfiles['size'][$i]);
    }
    unset($allfiles);
    return $this->files=$files;
}
private function minimilize($savefile){
    $image=new Gmagick($savefile);
    $width=$image->getimagewidth();
    $height=$image->getimageheight();
    $standartWidth='';
    $standartHeight='';
    $x='';
    $y='';
    if($width>$height) {
        $standartWidth=1024;
        $standartHeight=756;
        $masWidth=1300;
        $masHeight=900;

        $kw=$width/$masWidth;
        $wx=$width/$kw;
        $image->setCompressionQuality(80);
        $image->profileimage('*',null);
        $image->resizeimage($wx, $wx, null, 1, true);

        $x = (($masWidth - $standartWidth) / 2);
        $y = (($masHeight - $standartHeight) / 2);
    }
    if($width<$height) {
        $standartWidth=1024;
        $standartHeight=756;
        $koef=$width/1024;
        $wx=$height/$koef;
        $image->setCompressionQuality(80);
        $image->profileimage('*',null);
        $image->resizeimage($wx, $wx, null, 1, true);
        $x = 0;
        $y = $wx/7.75;
    }
    $image->cropimage($standartWidth, $standartHeight, $x,$y);
    $image->writeimage($savefile);
    $image->destroy();
}
private function saveEvent(){
    $event=mb_substr(sha1(date('YmdHis')), 0,10);
    $Head="img/"."$event";
    mkdir($Head,0777,true);
    chmod($Head, 0777);
    $AllWaySavefiles=[];
    $LengthDaunloadFiles=count($this->files)-1;
    for ($i=$LengthDaunloadFiles;$i>=0;$i--)
    {
        $newname = mb_substr(sha1(date('YmdHis',time()).mt_rand().$this->files[$i]),0,7).'.jpeg';
        $savefile=$Head.'/'."$newname";
        move_uploaded_file($this->files[$i],$savefile);
        unset($this->files[$i]);
        chmod($savefile, 0777);
        self::minimilize($savefile);
        $AllWaySavefiles[]=$savefile;
    }
    return  $this->AllWaySavefiles=$AllWaySavefiles;
}

}

READ ALSO
Как сделать сайт на AngularJS 1.5 + PHP доступным для поисковиков (Yandex, Google и тд)

Как сделать сайт на AngularJS 1.5 + PHP доступным для поисковиков (Yandex, Google и тд)

Создал сайт на angularjs, но столкнулся с проблемой индексацииПрочитал кучу инструкций, но не смог наиболее актуальный и не платный

167
Как изменить переменную, по условию if&hellip;else.

Как изменить переменную, по условию if…else.

Есть переменная "$dates"В html-форме есть DatePicker с именем "datetime"

171
PHP ошибки с кодировкой

PHP ошибки с кодировкой

Загружаю json данные со стороннего сайта, некоторые символы приходят в UNICOD (точнее переменные в JSON) примерно таком:

149
Как использовать OpenCL в программе?

Как использовать OpenCL в программе?

Загрузил AMD SDKв папке \include\SDKUtil лежат куча *

233