Generate a thumbnail.

@param array $thumbnail

@return bool Returns true if success, false on failure
975395
private function generateThumbnail(array $thumbnail)
    {
        $file = $this->getEntityManager()->find(File::class, $thumbnail['fileID']);

        if ($this->attemptBuild($file, $thumbnail)) {
            $result = true;
        } else {
            $this->failBuild($file, $thumbnail);
            $result = false;
        }

        return $result;
    }
758806
public function makeThumbnail($prefix, array $config)
    {
        $defaultConfig = [
            'jpeg_quality' => 100
        ];
        $config = array_merge($defaultConfig, $config);

        $width = !empty($config['w']) ? $config['w'] : null;
        $height = !empty($config['h']) ? $config['h'] : null;

        $image = $this->ImageManager->make($this->Path->fullPath());

        if (!empty($config['orientate'])) {
            $image = $this->orientate($image);
        }

        if (!empty($config['crop'])) {
            $image = $this->thumbnailCrop($image, $width, $height);
        } elseif (!empty($config['fit'])) {
            $image = $this->thumbnailFit($image, $width, $height);
        } elseif (!empty($config['custom'])) {
            $image = $this->thumbnailCustom($image, $config['custom'], $config['params']);
        } else {
            $image = $this->thumbnailResize($image, $width, $height);
        }

        unset($config['crop'], $config['w'], $config['h'], $config['custom'], $config['params'], $config['orientate']);

        $image->save($this->Path->fullPath($prefix), $config['jpeg_quality']);

        return $this->Path->fullPath($prefix);
    }
1170577
public function refresh(Thumbnail $thumbnail)
    {
        $generatorClassNames = static::getThumbnailGeneratorClassNames($this->objectManager);
        foreach ($generatorClassNames as $generator) {
            $generator = $this->objectManager->get($generator['className']);
            if (!$generator->canRefresh($thumbnail)) {
                continue;
            }
            $generator->refresh($thumbnail);
            return;
        }
    }
560592
public function create_thumbnail($width = 200, $height = 200, $bestfit = false, $fill = false)
    {

        if (empty($this->imagemagik) || empty($this->filename)) return false;
        try {
            $this->imagemagik->thumbnailimage($width, $height, $bestfit, $fill);
        } catch (\ImagickException $e) {
            throw $e;
        }

        return true;
    }
1374345
def save_thumbnail(self, thumbnail):
        
        filename = thumbnail.name
        try:
            self.thumbnail_storage.delete(filename)
        except Exception:
            pass
        self.thumbnail_storage.save(filename, thumbnail)

        thumb_cache = self.get_thumbnail_cache(
            thumbnail.name, create=True, update=True)

        # Cache thumbnail dimensions.
        if settings.THUMBNAIL_CACHE_DIMENSIONS:
            dimensions_cache, created = (
                models.ThumbnailDimensions.objects.get_or_create(
                    thumbnail=thumb_cache,
                    defaults={'width': thumbnail.width,
                              'height': thumbnail.height}))
            if not created:
                dimensions_cache.width = thumbnail.width
                dimensions_cache.height = thumbnail.height
                dimensions_cache.save()

        signals.thumbnail_created.send(sender=thumbnail)
246020
public function setThumbnailsFormat($thumbnailsFormat)
    {
        $thumbnailsFormat = strtolower(trim((string) $thumbnailsFormat));
        if ($thumbnailsFormat !== ThumbnailFormatService::FORMAT_AUTO) {
            if (!$this->app->make(BitmapFormat::class)->isFormatValid($thumbnailsFormat)) {
                $thumbnailsFormat = BitmapFormat::FORMAT_JPEG;
            }
        }
        $this->thumbnailsFormat = $thumbnailsFormat;

        return $this;
    }
744098
public function generateThumbnails(File $file, $thumbnailLinks = false)
    {
        $links = [];
        if (!$file->getIsImage()) {
            return $links;
        }
        $generator = $this->getThumbnailGenerator();

        // Small thumbnail
        $smallWidth = UploadField::config()->uninherited('thumbnail_width');
        $smallHeight = UploadField::config()->uninherited('thumbnail_height');

        // Large thumbnail
        $width = $this->config()->get('thumbnail_width');
        $height = $this->config()->get('thumbnail_height');

        // Generate links if client requests them
        // Note: Thumbnails should always be generated even if links are not
        if ($thumbnailLinks) {
            $links['smallThumbnail'] = $generator->generateThumbnailLink($file, $smallWidth, $smallHeight);
            $links['thumbnail'] = $generator->generateThumbnailLink($file, $width, $height);
        } else {
            $generator->generateThumbnail($file, $smallWidth, $smallHeight);
            $generator->generateThumbnail($file, $width, $height);
        }

        $this->extend('updateGeneratedThumbnails', $file, $links, $generator);
        return $links;
    }
793085
public function get_thumbnail($filepath, $thumbsize) {
        global $CFG;

        $filepath = trim($filepath, '/');
        $origfile = $this->get_rootpath() . $filepath;
        // As thumbnail filename we use original file content hash.
        if (!$this->is_in_repository($filepath) || !($filecontents = @file_get_contents($origfile))) {
            // File is not found or is not readable.
            return null;
        }
        $filename = file_storage::hash_from_string($filecontents);

        // Try to get generated thumbnail for this file.
        $fs = get_file_storage();
        if (!($file = $fs->get_file(SYSCONTEXTID, 'repository_filesystem', $thumbsize, $this->id, '/' . $filepath . '/',
                $filename))) {
            // Thumbnail not found . Generate and store thumbnail.
            require_once($CFG->libdir . '/gdlib.php');
            if ($thumbsize === 'thumb') {
                $size = 90;
            } else {
                $size = 24;
            }
            if (!$data = generate_image_thumbnail_from_string($filecontents, $size, $size)) {
                // Generation failed.
                return null;
            }
            $record = array(
                'contextid' => SYSCONTEXTID,
                'component' => 'repository_filesystem',
                'filearea' => $thumbsize,
                'itemid' => $this->id,
                'filepath' => '/' . $filepath . '/',
                'filename' => $filename,
            );
            $file = $fs->create_file_from_string($record, $data);
        }
        return $file;
    }
147863
protected function buildThumbnails($files)
    {
        $thumbnails = [];

        foreach ($files as $file) {
            if (file_can_have_thumbnail($file)) {
                $thumbnails[$file] = (string) $this->image
                    ->make(Storage::get($file))
                    ->resize(20, 20)->encode('data-url');
            }
        }

        return $thumbnails;
    }
717573
public function thumbnail($size = 'post-thumbnail', $attr = '', $post = null)
    {
        if (is_null($post)) {
            $post = $this->id();
        }

        return get_the_post_thumbnail($post, $size, $attr);
    }
965445
public function storeTemporaryThumbnail (Thumbnail $thumbnail)
    {
        $json = $this->storeGenericMedia(MediaType::THUMBNAIL, false, $thumbnail);

        return (new Uploaded\Thumbnail($json->thumb_media_id))
            ->withExpiresDate($this->createExpiryDate($json->created_at));
    }
40720
public function thumbnailURL($size = 'large')
    {
        if (!in_array($size, ['large', 'medium', 'small'])) {
            return false;
        }

        $info = $this->parseLink();
        $service = $this->getService();

        if (!$info || !$service) {
            return false;
        }

        if ($service == 'YouTube') {
            if ($size == 'large') {
                $img = 'hqdefault.jpg';
            } elseif ($size == 'medium') {
                $img = 'mqdefault.jpg';
            } else {
                $img = 'default.jpg';
            }
            return 'https://i.ytimg.com/vi/' . $this->VideoID . '/' . $img;
        }

        if ($service == 'Vimeo') {
            $data = $this->getCachedJsonResponse(
                'https://vimeo.com/api/v2/video/' . $this->VideoID . '.json'
            );

            if (!$data) {
                return false;
            }

            if ($size == 'large' && (!empty($data[0]['thumbnail_large']))) {
                return $data[0]['thumbnail_large'];
            } elseif ($size == 'medium' && (!empty($data[0]['thumbnail_medium']))) {
                return $data[0]['thumbnail_medium'];
            } elseif (!empty($data[0]['thumbnail_small'])) {
                return $data[0]['thumbnail_small'];
            }
        }

        return false;
    }
108126
public function generateThumbnail(AssetContainer $file, $width, $height)
    {
        if (!$file->getIsImage() || !$file->exists()) {
            return null;
        }

        // Disable generation if only querying existing files
        if (!$this->getGenerates()) {
            $file = $file->existingOnly();
        }

        // Make large thumbnail
        return $file->FitMax($width, $height);
    }
193062
private function thumbnail(array $params)
    {
        $mode = isset($params['mode']) ? $params['mode'] : self::THUMBNAIL_OUTBOUND;

        $width = (isset($params['width']) && is_numeric($params['width'])) ? $params['width'] : null;
        $height = (isset($params['height']) && is_numeric($params['height'])) ? $params['height'] : null;

        if (is_null($width) || is_null($height)) {
            throw new Exception('Wrong thumbnail width or height');
        }

        $this->image = $this->image->thumbnail(new Box($width, $height), $mode);
    }
907099
def set_thumbnail(self, thumbnail):
        
        headers = {
            "Authorization": "token {}".format(self._client.token),
            "Content-type": "image/png",
        }

        # TODO this check needs to be smarter - python2 doesn't do it right
        if not isinstance(thumbnail, bytes):
            with open(thumbnail, 'rb') as f:
                thumbnail = f.read()

        result = requests.put('{}/{}/thumbnail'.format(self._client.base_url,
                OAuthClient.api_endpoint.format(id=self.id)),
                headers=headers, data=thumbnail)

        if not result.status_code == 200:
            errors = []
            j = result.json()
            if 'errors' in j:
                errors = [ e['reason'] for e in j['errors'] ]
            raise ApiError('{}: {}'.format(result.status_code, errors), json=j)

        return True
44018
public static function generateThumbnail($fileName, $data = [])
    {
        FileHelper::createDirectory( \Yii::getAlias('@thumbnail') . '/' . date('Y/m/d'));
        $thumbnail_save =  \Yii::getAlias('@thumbnail') . '/' . $fileName;
        $size_width = get_setting_value('media_configuration', 'thumbnail_size_width', 150);
        $size_height = get_setting_value('media_configuration', 'thumbnail_size_height', 150);
        Image::getImagine()
            ->open(self::getFileNameSave($fileName))
            ->thumbnail(new Box($size_width, $size_height))
            ->save($thumbnail_save , ['quality' => self::getQualitySetting(50, $data)]);

        FileHelper::createDirectory(\Yii::getAlias('@medium') . '/' . date('Y/m/d'));
        $thumbnail_save = \Yii::getAlias('@medium') . '/' . $fileName;
        $size_width = get_setting_value('media_configuration', 'medium_size_width', 150);
        $size_height = get_setting_value('media_configuration', 'medium_size_height', 150);
        Image::getImagine()
            ->open(self::getFileNameSave($fileName))
            ->thumbnail(new Box($size_width, $size_height))
            ->save($thumbnail_save , ['quality' => self::getQualitySetting(50, $data)]);

        FileHelper::createDirectory(\Yii::getAlias('@large') . '/' . date('Y/m/d'));
        $thumbnail_save = \Yii::getAlias('@large') . '/' . $fileName;
        $size_width = get_setting_value('media_configuration', 'large_size_width', 150);
        $size_height = get_setting_value('media_configuration', 'large_size_height', 150);
        Image::getImagine()
            ->open(self::getFileNameSave($fileName))
            ->thumbnail(new Box($size_width, $size_height))
            ->save($thumbnail_save , ['quality' => self::getQualitySetting(50, $data)]);
    }
790121
private function findOriginalFileFromThumbnail(string $thumbnail): string
    {
        // First option - a file with the same name
        $original = str_replace('/thumbs/', '/', $thumbnail);

        // Second option - a .PNG thumbnail for some other image type
        if (substr_compare($original, '.png', -4, 4) === 0) {
            $pattern = substr($original, 0, -3) . '*';
            $matches = glob($pattern, GLOB_NOSORT);
            if (!empty($matches) && is_file($matches[0])) {
                $original = $matches[0];
            }
        }

        return $original;
    }