Builds thumb uploader

@param string $dir Target directory
@param integer $quality Desired quality for thumbs
@param array $options
@return \Krystal\Image\Tool\Upload\Plugin\ThumbFactory
745
public function build($dir, $quality, array $options = array())
    {
        // Alter default quality on demand
        if (isset($options['quality'])) {
            $quality = $options['quality'];
        }

        return new Thumb($dir, $options['dimensions'], $quality);
    }
365225
public function generate(string $resourceId, string $thumbId, $quality = 100)
    {
        $setting = $this->getThumbSettings($thumbId);

        $this->setThumbFolderName($setting);

        $resource = $this->getResource($resourceId);

        $file = $this->getOriginalFile($resource);

        if( $file ) {
            $image = $this->resizeImage($file, $setting);
//            $image = $this->addWatermark($image, $setting);
            $image->encode('jpg', $quality);
            $image->save($this->getLocation($resource));
        }
    }
617375
public function buildCreateForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('files', DropzoneType::class, [
                'mapped' => false,
                'path' => $this->router->generate('opifer_api_media_upload'),
                'form_action' => $this->router->generate('opifer_media_media_updateall'),
                'label' => '',
            ])
        ;
    }
551097
public function scan($directory, array $options = array())
    {
        set_time_limit(0);

        $options += array(
            'sort' => null,
            'order' => null,
            'filter_key' => null,
            'filter_value' => null
        );

        $result = null;
        $this->hook->attach('module.file_manager.scan.before', $directory, $options, $result, $this);

        if (isset($result)) {
            return $result;
        }

        $filters = $this->getFilters();
        $iterator = new Filter(new FilesystemIterator($directory), $options, $filters);

        if (!empty($options['count'])) {
            return iterator_count($iterator);
        }

        if (!empty($options['limit'])) {
            list($page, $limit) = $options['limit'];
            $iterator = new LimitIterator($iterator, $page, $limit);
        }

        $result = iterator_to_array($iterator);
        $this->sort($result, $options['sort'], $options['order']);

        $this->hook->attach('module.file_manager.scan.after', $directory, $options, $result, $this);
        return $result;
    }
1190764
public function buildThumb($width = null, $height = null)
    {
        /* @var Gallery $plugin */
        $plugin = $this->getTable()->getPlugin();

        $filename = $this->getPdoValue('image');
        $thumb = PhpThumbFactory::create($plugin->getDataDir() . '/' . $filename);

        $thumb->resize(
            $width ? $width : $plugin->settings['thumbWidth'],
            $height ? $height : $plugin->settings['thumbHeight']);
        $thumb->save($plugin->getDataDir() . '/' . $this->getPdoValue('thumb'));
    }
515818
static public function buildDir($dirlist)
    {
        $appPath = static::getAppPath();
        
        $dirlist = (array) $dirlist;
        foreach ($dirlist as $dir) {
            $path = rtrim($appPath, '\\/') . '/' . trim($dir, '\\/');
            if (!is_dir($path)) {
                mkdir($path, 0755, true);
            }
        }
    }
651224
public static function make($dir, $mode = 0755)
    {
        if (\is_dir($dir) || \mkdir($dir, $mode, true)) {
            return true;
        }
        if (!self::make(\dirname($dir), $mode)) {
            return false;
        }
        return \mkdir($dir, $mode);
    }
1087203
public function saveSnapshot($dir){
        
        if(!is_dir($dir)){
            mkdir($dir, 0775, true);
        }
        
        $jpeg = $this->takeSnapShot();
        $file = $dir.'/'.date('Y_m_d_H_i_s').'.jpg';
        if(file_put_contents($file, $jpeg)){
            return $file;
        }
        
        return '';
    }
1203723
protected function uploadFile($options)
    {
        // If upload path not specified InvalidArgumentException will throw.
        if (!(isset($this->fileInfo['params']['destination'])
            && !empty($this->fileInfo['params']['destination']))
        ) {
            $this->error[] = 'Upload path required';

            return false;
        }

        if (isset($this->fileInfo['file']['name'])) {
            $this->setPathInfo();
        }

        if (isset($this->filePathInfo['extension'])) {

            // If invalid file uploaded return collect error.
            if (
            !in_array(
                strtolower($this->filePathInfo['extension']),
                array_map('strtolower', $this->fileInfo['ext'])
            )
            ) {
                $this->error[] = 'Invalid file format. Valid file format: '.implode(',', $this->fileInfo['ext']);

                return false;
            }
        }

        if (isset($this->fileInfo['file']['size']) &&
            $this->fileInfo['file']['size'] <= $this->getNumericfileSize($this->fileInfo['size'])
        ) {
            $path = str_replace(
                '/',
                DS,
                $this->getRootDir().DS.$this->fileInfo['params']['destination'].DS.$this->getFileName($options)
            );
            
            if (!is_writable($path)) {
                $this->error[] = "$path should exists and must be writable.";

                return false;
            }

            if (!is_writable($path)) {
                $this->error[] = "$path should exists and must be writable.";

                return false;
            }

            try {
                if (move_uploaded_file($this->fileInfo['file']['tmp_name'], $path) === true) {
                    return true;
                }
            } catch (\ErrorException $e) {
                // If file was not uploaded we will catch error.
                $this->error[] = $e->getMessage();

                return false;
            }
        } else {
            // If file size was too large  OutofRange exception will throw.
            $this->error[] =
                $this->fileInfo['file']['name'].' is too large.Exceeds upload limit '.$this->fileInfo['size'];

            return false;
        }
    }
88062
public static function makeThumbnail($uploadDir, $image, $thumbnailPath, $thumbnailWords)
    {
        $thumbnailWidth = 50;
        $thumbnailHeight = 50;
        $arrayImageDetail = getimagesize("$uploadDir"."$image");
        $originalWidth = $arrayImageDetail[0];
        $originalHeight = $arrayImageDetail[1];

        if ($originalWidth > $originalHeight) {
            $newWidth = $thumbnailWidth;
            $newHeight = intval($originalHeight * $newWidth / $originalWidth);
        } else {
            $newHeight = $thumbnailHeight;
            $newWidth = intval($originalWidth * $newHeight / $originalHeight);
        }

        $varX = intval(($thumbnailWidth - $newWidth) / 2);
        $varY = intval(($thumbnailHeight - $newHeight) / 2);

        if ($arrayImageDetail[2] == 1) {
            $imageType = "ImageGIF";
            $createFrom = "ImageCreateFromGIF";
        } elseif ($arrayImageDetail[2] == 2) {
            $imageType = "ImageJPEG";
            $createFrom = "ImageCreateFromJPEG";
        } elseif ($arrayImageDetail[2] == 3) {
            $imageType = "ImagePNG";
            $createFrom = "ImageCreateFromPNG";
        }

        if ($imageType) {
            $oldImage = $createFrom("$uploadDir"."$image");
            $newImage = imagecreatetruecolor($thumbnailWidth, $thumbnailHeight);
            imagecopyresized($newImage, $oldImage, $varX, $varY, 0, 0, $newWidth, $newHeight, $originalWidth, $originalHeight);
            $imageType($newImage, "$thumbnailPath"."$thumbnailWords".'_'."$image");
        }

        return "$thumbnailWords".'_'."$image";
    }
1228762
public function _dirCreate($dir, $mode = 0755)
    {
        /** @noinspection NotOptimalIfConditionsInspection */
        if (!is_dir($dir) && !@mkdir($dir, $mode, true) && !is_dir($dir)) {
            throw new CreateDirectoryFailedException(['create `:dir` directory failed: :last_error_message', 'dir' => $dir]);
        }
    }
593922
public function upload($file, array $options = [])
    {
        $filename = sprintf('%s-%s', rand(100, 999), $file->getClientOriginalName());
        return Storage::putFileAs($this->uploadFolder, $file, $filename);
    }
1192483
public function thumbnail($media, $format, $options = [])
    {
        if (!$media) {
            return '';
        }

        $provider = $this->getProvider($media);

        $format = $provider->getFormatName($media, $format);
        $formatDefinition = $provider->getFormat($format);

        // build option
        $options = array_merge([
            'title' => $media->getName(),
            'width' => $formatDefinition['width'],
        ], $options);

        $options['src'] = $provider->generatePublicUrl($media, $format);

        return $this->getTemplating()->render($provider->getTemplate('helper_thumbnail'), [
            'media' => $media,
            'options' => $options,
        ]);
    }
876477
public function createDir($dir, $type='sandbox')
	{
		$url = 'https://api.dropbox.com/1/fileops/create_folder';
		$result = $this->doOAuthCall($url, 'POST', array('path'=>$dir), $type);
		$result_body = json_decode($result['body'], true);
		if (!array_key_exists('error', $result_body)) {
			return $result_body;
		} else {
			trigger_error(sprintf(self::E_APIERROR, $result_body['error']));
			return false;
		}
	}
721201
protected function makeImage($file = null, $quality = null)
  {
    $dir = dirname($file);
    if (!is_dir($dir)) {
      mkdir($dir, 0777, true);
    }

    switch ($this->getTypeByFile($file)) {
      case IMG_JPG:
        return imagejpeg($this->image, $file, $quality ? : static::QUALITY_JPG);
        break;
      case IMG_PNG:
        return imagepng($this->image, $file, $quality ? : static::QUALITY_PNG);
        break;
      case IMG_GIF:
        return imagegif($this->image, $file);
        break;
      default:
        Ex::ThrowError(Ex::BAD_TYPE);
    }
  }
1203088
public function thumb($thumbWidth, $thumbHeight, $isCut = true, $cutPlace = 5, $quality = 95, $thumbType = 'jpg') 
    {
        if (!in_array($thumbType, ['jpg', 'png', 'webp'])) {
            throw new Exception('thumb image type must be webp|jpg|png');
        }
	
        if($isCut) {
            return $this->thumbCutOut($thumbWidth, $thumbHeight, $cutPlace, $quality, $thumbType);
        } else {
            return $this->thumbUnCut($thumbWidth, $thumbHeight, $quality, $thumbType);
        }
    }
410255
public function setOutdir($dir)
    {
        parent::setOutdir($dir);
        $this->storage->setOutdir($dir);

        return $this;
    }