Generate thumbnail and return the "src" property for this thumbnail

@param AssetContainer|DBFile|File $file
@param int $width
@param int $height
@return string
326653
public function generateThumbnailLink(AssetContainer $file, $width, $height)
    {
        $thumbnail = $this->generateThumbnail($file, $width, $height);

        return $this->generateLink($thumbnail);
    }
978462
public function thumbnail($width = 50, $height = 50, $fit = 'outbound') {
        return $this->addTransformation(
            sprintf('thumbnail:width=%d,height=%s,fit=%s', (int) $width, (int) $height, $fit)
        );
    }
1082670
public function getURL($width = '', $height = '')
    {
        $uri = $this->getName();
        if ($height && $width) {
            return Settings::get('image_url').$width.'/'.$height.'/'.$uri;
        } elseif ($width) {
            return Settings::get('image_url').$width.'/'.$uri;
        } else { // original image
            return Settings::get('image_url').$uri;
        }
    }
895159
protected function getImageSize($width, $height)
    {
        $min = min($width, $height);

        // if one value is zero, we have to calculate the right
        // value using the image aspect raion
        if (0 === $min) {

            // if both hight and widh are zero we assume
            // that the image is not resized at all
            if (0 === max($width, $height)) {
                extract($this->getInfo());
            } else {
                $ratio = $this->getInfo('ratio');
            }

            $width  = $width  === 0 ? (int) floor($height * $ratio) : $width;
            $height = $height === 0 ? (int) floor($width  / $ratio) : $height;
        }

        return compact('width', 'height');
    }
271004
public function createImage($width, $height, $format)
    {
        $image = new \Imagick();
        $pixel = new \ImagickPixel('none');
        $image->newImage(intval($width), intval($height), $pixel);
        $image->setImageFormat($format);
        $this->colorNumber = $image->getImageColors();
        $this->pixelNumber = 0;
        $content = $image->getimageblob();
        $image->destroy();
        unset($image);
        return $content;
    }
1048109
public function getResizedImage(
        File $file,
        $urlType = 'default',
        $width = 100,
        $height = null,
        $crop = true,
        $filename = null,
        $quality = null
    ) {
        if ($crop) {
            return $this->getCroppedImage($file, $urlType, $width, $height, $filename, $quality);
        }

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

        if ($this->repository) {
            if ($file->isImage()) {
                $filename = $this->determineFileName($file, $width, $height, 'r', $filename);

                if ($this->mustBuildImage($file, $filename)) {
                    $binary = $this->getBinary($file);

                    if ($this->keepOriginalImage($binary, $width, $height)) {
                        return $this->getOriginalImage($file, $urlType, $filename);
                    }

                    if ($binary) {
                        $imagine = new Imagine();
                        $image   = $imagine->load($binary);

                        $image->resize(new Box($width, $height));

                        $quality = $this->determineQuality($quality);
                        $image->save($this->basePath . '/' . $filename, array('quality' => $quality));
                    } else {
                        return false;
                    }
                }

                $url = $this->baseUrl . '/' . $filename;
                $file->addUrl($urlType, $url);

                return $file;
            }
        }

        return false;
    }
21016
public function newImage($width, $height, $background = null)
    {
        $background = new Color($background);

        // create empty core
        $core = new \Imagick;
        $core->newImage($width, $height, $background->getPixel(), 'png');
        $core->setType(\Imagick::IMGTYPE_UNDEFINED);
        $core->setImageType(\Imagick::IMGTYPE_UNDEFINED);
        $core->setColorspace(\Imagick::COLORSPACE_UNDEFINED);

        // build image
        return new Image(new static, $core);
    }
44165
public function image(String $src, Int $width = NULL, Int $height = NULL, Array $attributes = []) : String
    {
        if( ! IS::url($src) )
        {
            $src = Request::getBaseURL($src);
        }

        $attributes['src'] = $src;

        if( ! empty($width) )
        {
            $attributes['width'] = $width;
        }

        if( ! empty($height) )
        {
            $attributes['height'] = $height;
        }

        if( ! isset($attributes['title']) )
        {
            $attributes['title'] = '';
        }

        if( ! isset($attributes['alt']) )
        {
            $attributes['alt'] = '';
        }

        return $this->_singleElement('img', $attributes);
    }
728622
public function canvas($width, $height, $background = null)
    {
        return $this->createDriver()->newImage($width, $height, $background);
    }
800986
public function resize($width, $height) {
		$image = imagecreatetruecolor($width, $height);
		imagealphablending($image, false);
		imagesavealpha($image, true);
		imagecopyresampled($image, $this->_image, 0, 0, 0, 0, $width, $height, $this->width, $this->height);
		imagedestroy($this->_image);
		$this->_image = $image;
		return $this;
	}
165344
public static function getInstanceByCreate($width, $height)
    {
        $instance = new self();

        // set image dimensions
        $instance->width = (int)$width;
        $instance->height = (int)$height;

        $instance->createImage();

        return $instance;
    }
32819
public function getPicUrl($file_id, $width = 0, $height = 0,$water=false, $crop = self::resize_rect_in,$blur=-1){
        $path=$this->config['base_path'].DIRECTORY_SEPARATOR.$file_id;
        return $this->config['cdn'].$path;
    }
461540
public function imageUrl($width, $height, $fit): string
    {
        // Sign the URL, to protect against mass-resize attacks.
        $glide_key = Site::getPreference('glide-key');
        if (empty($glide_key)) {
            $glide_key = bin2hex(random_bytes(128));
            Site::setPreference('glide-key', $glide_key);
        }

        if (Auth::accessLevel($this->media->tree()) > $this->media->tree()->getPreference('SHOW_NO_WATERMARK')) {
            $mark = 'watermark.png';
        } else {
            $mark = '';
        }

        $url_builder = UrlBuilderFactory::create(WT_BASE_URL, $glide_key);

        $url = $url_builder->getUrl('index.php', [
            'route'     => 'media-thumbnail',
            'xref'      => $this->media->xref(),
            'ged'       => $this->media->tree()->name(),
            'fact_id'   => $this->fact_id,
            'w'         => $width,
            'h'         => $height,
            'fit'       => $fit,
            'mark'      => $mark,
            'markh'     => '100h',
            'markw'     => '100w',
            'markalpha' => 25,
            'or'        => 0,
            // Intervention uses exif_read_data() which is very buggy.
        ]);

        return $url;
    }
378269
public function thumbnailAction($storageId, $height, $width)
    {
        $fileManager = $this->get('beaast.core.manager.file');

        /**
         * @var File $file
         */
        $file = $fileManager->findOneBy(['storageId' => $storageId]);

        if (!$file || !in_array($file->getExtension(), ['jpg', 'png', 'gif'], true)) {
            throw $this->createNotFoundException();
        }

        $filePath = $fileManager->getFilePath($file);

        $cacheFileName = 'thumbnail_'.$height.'_'.$width.'_'.$storageId.'.'.$file->getExtension();

        $cacheFilePath = $this->getParameter('kernel.root_dir').'/../var/storage/cache/'.$cacheFileName;
        if (!file_exists($cacheFilePath) && file_exists($filePath)) {
            $imagick = new \Imagick($filePath);
            $imagick->thumbnailImage($width, $height, true);
            file_put_contents($cacheFilePath, $imagick->getImageBlob());
        }

        return $this->cacheAction($cacheFileName);
    }
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'));
    }
659052
public function showResource (string $id = null, int $width = 0, int $height = 0, bool $fit = false)
    {
        $storagePath = storage_path ('app/');

        if (is_null ($id))
            return HCLog::error ('R-001', trans ('resources::resources.errors.resource_id_missing'));

        // cache resource for 10 days
        $resource = \Cache::remember($id, 14400, function () use ($id) {
            return HCResources::find ($id);
        });

        if (!$resource)
            return HCLog::error ('R-003', trans ('resources::resources.errors.resource_not_found'));

        if (!Storage::exists ($resource->path))
            HCLog::stop (trans ('resources::resources.errors.resource_not_found_in_storage') . ' : ' . $id);

        $cachePath = generateResourceCacheLocation ($resource->id, $width, $height, $fit) . $resource->extension;

        if (file_exists ($cachePath)) {
            $resource->size = File::size ($cachePath);
            $resource->path = $cachePath;
        } else {

            switch ($resource->mime_type) {
                case 'image/png' :
                case 'image/jpeg' :
                case 'image/jpg' :

                    if ($width != 0 && $height != 0) {

                        createImage ($storagePath . $resource->path, $cachePath, $width, $height, $fit);

                        $resource->size = File::size ($cachePath);
                        $resource->path = $cachePath;
                    } else
                        $resource->path = $storagePath . $resource->path;
                    break;

                case 'video/mp4' :

                    $previewPath     = str_replace ('-', '/', $resource->id);
                    $fullPreviewPath = $storagePath . 'video-previews/' . $previewPath;

                    $cachePath = generateResourceCacheLocation ($previewPath, $width, $height, $fit) . '.jpg';

                    if (file_exists ($cachePath)) {
                        $resource->size      = File::size ($cachePath);
                        $resource->path      = $cachePath;
                        $resource->mime_type = 'image/jpg';
                    } else {

                        if ($width != 0 && $height != 0) {

                            $videoPreview = $fullPreviewPath . '/preview_frame.jpg';

                            //TODO: generate 3-5 previews and take the one with largest size
                            $this->generateVideoPreview ($resource, $storagePath, $previewPath);

                            createImage ($videoPreview, $cachePath, $width, $height, $fit);

                            $resource->size      = File::size ($cachePath);
                            $resource->path      = $cachePath;
                            $resource->mime_type = 'image/jpg';
                        } else
                            $resource->path = $storagePath . $resource->path;
                    }
                    break;

                default:

                    $resource->path = $storagePath . $resource->path;
                    break;
            }
        }

        // Show resource
        header ('Pragma: public');
        header ('Cache-Control: max-age=86400');
        header ('Expires: ' . gmdate ('D, d M Y H:i:s \G\M\T', time () + 86400));
        header ('Content-Length: ' . $resource->size);
        header ('Content-Disposition: inline;filename="' . $resource->original_name . '"');
        header ('Content-Type: ' . $resource->mime_type);
        readfile ($resource->path);

        exit;
    }
839728
protected function getCroppedImage(
        File $file,
        $urlType = 'default',
        $width = 100,
        $height = null,
        $filename = null,
        $quality = null
    ) {
        if ($height == null) {
            $height = $width;
        }

        if ($this->repository) {
            if ($file->isImage()) {

                $filename = $this->determineFileName($file, $width, $height, 'c', $filename);

                if ($this->mustBuildImage($file, $filename)) {
                    $binary = $this->getBinary($file);

                    if ($this->keepOriginalImage($binary, $width, $height)) {
                        return $this->getOriginalImage($file, $urlType, $filename);
                    }

                    if ($binary) {
                        $imagine = new Imagine();
                        $image   = $imagine->load($binary);

                        $size = $image->getSize();

                        $ratioOriginal = $size->getWidth() / $size->getHeight();

                        if ($ratioOriginal > ($width / $height)) {
                            // create image that has the desired height and an oversize width to crop from
                            $y = $height;
                            $x = $size->getWidth() * ($y / $size->getHeight());

                            $size = new Box($x, $y);

                            $image->resize($size);

                            $start = (int)(($x - $width) / 2);

                            $upperLeft = new Point($start, 0);

                            $image->crop($upperLeft, new Box ($width, $height));
                        } else {

                            // create image that has the desired width and an oversize height to crop from
                            $x = $width;
                            $y = $size->getHeight() * ($x / $size->getWidth());

                            $size = new Box($x, $y);
                            $image->resize($size);

                            $start = (int)(($y - $height) / 2);

                            $upperLeft = new Point(0, $start);

                            $image->crop($upperLeft, new Box ($width, $height));
                        }

                        $quality = $this->determineQuality($quality);
                        $image->save($this->basePath . '/' . $filename, array('quality' => $quality));
                    } else {
                        return false;
                    }
                }

                $url = $this->baseUrl . '/' . $filename;
                $file->addUrl($urlType, $url);

                return $file;
            }
        }

        return false;
    }