src/Operation/Operation.php
protected function makeResize(ARef $aRef, ImageSettingInterface $imageSetting, ResizeSettingInterface $resizeSetting, array $item_attrs = [], $tmp = false)
    {
        if($tmp)
        {
            $images_dir = $this->pathResolver->getTmpDir();
        }
        else
        {
            $images_dir = $this->pathResolver->getImageDir();
        }

        if (!is_readable($images_dir))
        {
            throw new OperationException('Дирректория картинок недоступна для чтения!');
        }

        if($tmp)
        {
            $resizes_dir = $this->pathResolver->getResizeTmpDir();
        }
        else
        {
            $resizes_dir = $this->pathResolver->getResizeDir();
        }

        if (!is_writable($resizes_dir))
        {
            throw new OperationException('Дирректория ресайзов недоступна для записи!');
        }

        $original_prefix = $this->getImagePrefix($imageSetting->getEntityName(), $aRef->getId(), $imageSetting->getName(), GenVariant::NONE);
        $original_file_path = $images_dir.'/'.$original_prefix;

        $original_file_name = false;

        foreach (glob($original_file_path.'.*') as $file)
        {
            if(is_dir($file))
            {
                continue;
            }

            $original_mime = File::mimeType($file);

            if($this->isVectorImage($original_mime))
            {
                throw new OperationException('Попытка выполнить ресайз векторного файла '.$file.'!');
            }

            $original_file_name = $file;

            break;
        }

        if(!$original_file_name)
        {
            throw new OperationException('Не найден файл цели для ресайза!');
        }

        $extension = File::extension($original_file_name);

        $width = $resizeSetting->getWidth();
        $height = $resizeSetting->getHeight();

        $img = ImageFacade::make($original_file_name);

        if($width or $height)
        {
            $aspectRatio = !($width and $height);

            if(!$width)
            {
                $width = null;
            }
            if(!$height)
            {
                $height = null;
            }

            $img = $img->resize($width, $height,
                function ($constraint) use ($aspectRatio)
                {
                    if($aspectRatio)
                    {
                        $constraint->aspectRatio();
                    }
                });
        }

        $this->modImage($img, $resizeSetting->getMods());

        $resize_prefix = $this->getImagePrefix($imageSetting->getEntityName(), $aRef->getId(), $imageSetting->getName(), GenVariant::RESIZE, $resizeSetting->getName());
        $resize_file_name = $resize_prefix.'.'.$extension;
        $resize_file_path = $resizes_dir.'/'.$resize_prefix.'.'.$extension;

        $img->save($resize_file_path, 100);

        chmod($resize_file_path, 0644);

        if(!$tmp)
        {
            $resizeImage = ImageFacade::make($resize_file_path);
            $width = $resizeImage->getWidth();
            $height = $resizeImage->getHeight();
            $item_attrs['link'] = $this->pathResolver->getResizePath().'/'.$resize_file_name;
            $item_attrs['width'] = $width;
            $item_attrs['height'] = $height;
            $this->dbAgent->resizeToDb($aRef, $imageSetting, $resizeSetting, $item_attrs);
        }
    }
protected function makeResize(ARef $aRef, ImageSettingInterface $imageSetting, ResizeSettingInterface $resizeSetting, array $item_attrs = [], $tmp = false)
    {
        if($tmp)
        {
            $images_dir = $this->pathResolver->getTmpDir();
        }
        else
        {
            $images_dir = $this->pathResolver->getImageDir();
        }

        if (!is_readable($images_dir))
        {
            throw new OperationException('Дирректория картинок недоступна для чтения!');
        }

        if($tmp)
        {
            $resizes_dir = $this->pathResolver->getResizeTmpDir();
        }
        else
        {
            $resizes_dir = $this->pathResolver->getResizeDir();
        }

        if (!is_writable($resizes_dir))
        {
            throw new OperationException('Дирректория ресайзов недоступна для записи!');
        }

        $original_prefix = $this->getImagePrefix($imageSetting->getEntityName(), $aRef->getId(), $imageSetting->getName(), GenVariant::NONE);
        $original_file_path = $images_dir.'/'.$original_prefix;

        $original_file_name = false;

        foreach (glob($original_file_path.'.*') as $file)
        {
            if(is_dir($file))
            {
                continue;
            }

            $original_mime = File::mimeType($file);

            if($this->isVectorImage($original_mime))
            {
                throw new OperationException('Попытка выполнить ресайз векторного файла '.$file.'!');
            }

            $original_file_name = $file;

            break;
        }

        if(!$original_file_name)
        {
            throw new OperationException('Не найден файл цели для ресайза!');
        }

        $extension = File::extension($original_file_name);

        $width = $resizeSetting->getWidth();
        $height = $resizeSetting->getHeight();

        $img = ImageFacade::make($original_file_name);

        if($width or $height)
        {
            $aspectRatio = !($width and $height);

            if(!$width)
            {
                $width = null;
            }
            if(!$height)
            {
                $height = null;
            }

            $img = $img->resize($width, $height,
                function ($constraint) use ($aspectRatio)
                {
                    if($aspectRatio)
                    {
                        $constraint->aspectRatio();
                    }
                });
        }

        $this->modImage($img, $resizeSetting->getMods());

        $resize_prefix = $this->getImagePrefix($imageSetting->getEntityName(), $aRef->getId(), $imageSetting->getName(), GenVariant::RESIZE, $resizeSetting->getName());
        $resize_file_name = $resize_prefix.'.'.$extension;
        $resize_file_path = $resizes_dir.'/'.$resize_prefix.'.'.$extension;

        $img->save($resize_file_path, 100);

        chmod($resize_file_path, 0644);

        if(!$tmp)
        {
            $resizeImage = ImageFacade::make($resize_file_path);
            $width = $resizeImage->getWidth();
            $height = $resizeImage->getHeight();
            $item_attrs['link'] = $this->pathResolver->getResizePath().'/'.$resize_file_name;
            $item_attrs['width'] = $width;
            $item_attrs['height'] = $height;
            $this->dbAgent->resizeToDb($aRef, $imageSetting, $resizeSetting, $item_attrs);
        }
    }
@param \Interpro\Core\Contracts\Ref\ARef $aRef
@param \Interpro\ImageAggr\Contracts\Settings\ImageSetting $imageSetting
@param \Interpro\ImageAggr\Contracts\Settings\ResizeSetting $resizeSetting
@param array $item_attrs
@param bool $tmp

@return void