Uploads a thumbnail for temporary storage on the WeChat servers.

@param Thumbnail $thumbnail

@return Uploaded\Thumbnail
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));
    }
648771
public static function thumbnailLink($content, $url = '#', $htmlOptions = array())
    {
        $itemOptions = TbArray::popValue('itemOptions', $htmlOptions, array());
        self::addCssClass('thumbnail', $htmlOptions);
        $content = self::link($content, $url, $htmlOptions);
        return self::tag('li', $itemOptions, $content);
    }
1085274
public function thumbnail($type)
    {
        // We take image from posts field
        $image = $this->attributes['image'];
        // We need to get extension type ( .jpeg , .png ...)
        $ext = pathinfo($image, PATHINFO_EXTENSION);
        // We remove extension from file name so we can append thumbnail type
        $name = rtrim($image, '.'.$ext);
        // We merge original name + type + extension
        return $name.'-'.$type.'.'.$ext;
    }
1135766
public function src()
    {
        $src = $this->thumbnail();

        if (!$src) {
            $src = $this->file();
        }

        return $this->createAbsoluteUrl($src);
    }
204443
protected function uploadScrawl()
    {
        /* 上传配置 */
        $config = [
            'maxFiles' => 1,
            'extensions' => $this->getSetting('imageAllowFiles'),
            'checkExtensionByMimeType' => false,
            "maxSize" => $this->options['imageMaxSize'],
            "oriName" => "scrawl.png"
        ];

        $uploader = new Uploader([
            'fileField' => $this->options['scrawlFieldName'],
            'config' => $config,
        ]);
        $uploader->upBase64();
        return $uploader->getFileInfo();
    }
490243
public function get_thumbnail()
    {
        $video_thumbnails = $this->entry->getVideoThumbnails();

        foreach ($video_thumbnails as $thumb) {
            if (120 == $thumb['width'] && 90 == $thumb['height']) {
                return $thumb['url'];
            }
        }
    }
1300440
public function addItem($src, $thumbnail=''){
        if(!$src) {
            return $this; 
        }

        if(!$this->data['list']) {
            $this->data['list'] = [];
        }

        $item = [];
        $item['src'] = $src;
        if($thumbnail) {
            $item['thumbnail'] = $thumbnail;
        }

        $this->data['list'][] = $item;
        return $this;
    }
62870
public function save()
    {
        if ($this->validate()) {
            $user = $this->getUser();

            $avatarPath = $this->getAvatarPath($user->id);
            $originalImage = $avatarPath . '_avatar.jpg';
            //保存原图
            Image::crop($this->file->tempName, $this->width, $this->height, [$this->x, $this->y])->save($originalImage, ['quality' => 100]);
            //缩放
            Image::thumbnail($originalImage, 200, 200)->save($avatarPath . '_avatar_big.jpg', ['quality' => 100]);
            Image::thumbnail($avatarPath . '_avatar_big.jpg', 128, 128)->save($avatarPath . '_avatar_middle.jpg', ['quality' => 100]);
            Image::thumbnail($avatarPath . '_avatar_big.jpg', 48, 48)->save($avatarPath . '_avatar_small.jpg', ['quality' => 100]);
            $user->avatar = true;
            $user->save();
            return true;
        }
        return false;
    }
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;
    }
783694
public function thumbnail($img, $outPath = '', $outFilename = '', $thumbWidth = '', $thumbHeight = '', $thumbType = '')
    {
        if (!$this->_checkImage($img) || $this->hasError()) {
            return $this;
        }

        $imgInfo = pathinfo($img);
        $rawImgType = $imgInfo['extension'];

        //基础配置
        $thumbType = $thumbType ?: $this->thumbOptions['type'];
        $thumbWidth = $thumbWidth ?: $this->thumbOptions['width'];
        $thumbHeight = $thumbHeight ?: $this->thumbOptions['height'];
        $outPath = $outPath ?: ($this->thumbOptions['path'] ?: \dirname($img));

        //获得图像信息
        list($imgWidth, $imgHeight) = getimagesize($img);
        $imgType = $this->_handleImageType($rawImgType);

        //获得相关尺寸
        $thumbSize = $this->_calcThumbSize($imgWidth, $imgHeight, $thumbWidth, $thumbHeight, $thumbType);

        //原始图像资源
        // imagecreatefromgif() imagecreatefrompng() imagecreatefromjpeg() imagecreatefromwbmp()
        $resImg = \call_user_func("imagecreatefrom{$imgType}", $img);

        //缩略图的资源
        if ($imgType === static::IMAGE_GIF) {
            $resThumb = imagecreate($thumbSize[0], $thumbSize[1]);
            $color = imagecolorallocate($resThumb, 255, 0, 0);
            imagecolortransparent($resThumb, $color); //处理透明色
        } else {
            $resThumb = imagecreatetruecolor($thumbSize[0], $thumbSize[1]);
            imagealphablending($resThumb, false); //关闭混色
            imagesavealpha($resThumb, true);      //储存透明通道
        }

        // 绘制缩略图X
        if (\function_exists('imagecopyresampled')) {
            imagecopyresampled($resThumb, $resImg, 0, 0, 0, 0, $thumbSize[0], $thumbSize[1], $thumbSize[2], $thumbSize[3]);
        } else {
            imagecopyresized($resThumb, $resImg, 0, 0, 0, 0, $thumbSize[0], $thumbSize[1], $thumbSize[2], $thumbSize[3]);
        }

        //配置输出文件名
        $outFilename = $outFilename ?: $this->thumbOptions['prefix'] . $imgInfo['filename'] . $this->thumbOptions['suffix'] . '.' . $rawImgType;
        $outFile = $outPath . DIRECTORY_SEPARATOR . $outFilename;

        if (!Directory::create($outPath)) {
            $this->_error = 'Failed to create the output directory path!. OUT-PATH: ' . $outPath;

            return $this;
        }

        // generate image to dst file. imagepng(), imagegif(), imagejpeg(), imagewbmp()
        \call_user_func("image{$imgType}", $resThumb, $outFile);

        imagedestroy($resImg);
        imagedestroy($resThumb);

        $this->working = [
            'raw' => $img,
            'out' => $outFile,
        ];

        $this->_result['workThumb']['rawFile'] = $img;
        $this->_result['workThumb']['outFile'] = $outFile;

        return $this;
    }
1016010
public function addNewsImage($url_source) {
		if($image = WechatNewsImage::findOne(['appid' => $this->app->appid, 'url_source' => $url_source])) {
			return $image->id;
		}

		$image = new WechatNewsImage;
		$image->url_source = $url_source;

		$data = $this->getData('/cgi-bin/media/uploadimg', [
			'access_token' => $this->getAccessToken(),
		], ['media' => '@' . $image->localFile]);
		$image->cleanTmp();

		if($this->errcode == 0) {
			$image->appid = $this->app->appid;
			$image->url = $data['url'];
			if($image->save()) {
				return $image->id;
			}
		}

		return 0;
	}
312173
public function thumbnail($size = [[80, 60]], $sep = '-', $replace = '') {
        $files = [];
        if ($this->file && !empty ($size)) {
            foreach ($size as $i => $s) {
                if (is_array($s) && isset ($s [0]) && isset ($s [1])) {
                    $width  = intval($s [0]);
                    $height = intval($s [1]);
                    if (!$sep) {
                        $tfile = $this->file;
                    } else {
                        if (isset($s[2])) {
                            $file  = $s[2];
                            $tfile = get_thumbnail_filename($this->file, $file, 0, $sep);
                        } else {
                            $tfile = get_thumbnail_filename($this->file, $width, $height, $sep);
                        }
                        if ($replace) {
                            $tfile = str_replace($replace, '', $tfile);
                        }
                        if (is_file($tfile)) {
                            $files [ $i ] = $tfile;
                            continue;
                        }
                    }
                    $image = new \image ($this->file);
                    $image->attach(new \image_fx_resize ($width, $height));
                    $rst = $image->save($tfile);
                    if (!$rst) {
                        log_warn('生成缩略图失败:' . $tfile, 'image_tool');
                    } else {
                        $files [ $i ] = $tfile;
                    }
                    $image->destroyImage();
                    if (!$sep) {
                        break;
                    }
                }
            }
        }

        return $files;
    }
111635
private function getDimensions($thumbnail)
    {
        $matches = null;
        if (preg_match('/^ccm_(\d+)x(\d+)(?:_([10]))?$/', $thumbnail['thumbnailTypeHandle'], $matches)) {
            return array_pad(array_slice($matches, 1), 3, 0);
        }
    }
703720
public static function resizeThumbnailImage($thumb_image_name, $image, $width, $height, $start_width, $start_height, $scale)
    {
        $newImageWidth = ceil($width * $scale);
        $newImageHeight = ceil($height * $scale);
        $newImage = imagecreatetruecolor($newImageWidth, $newImageHeight);
        $source = imagecreatefromjpeg($image);
        imagecopyresampled($newImage, $source, 0, 0, $start_width, $start_height, $newImageWidth, $newImageHeight, $width, $height);
        imagejpeg($newImage, $thumb_image_name, 90);
        chmod($thumb_image_name, 0777);

        return $thumb_image_name;
    }
954286
public function actionUpload()
    {
        Yii::$app->response->format = Response::FORMAT_JSON;

        $model = new Mediafile();
        $routes = $this->module->routes;
        $rename = $this->module->rename;
	    $tagIds = Yii::$app->request->post('tagIds');

	    if ($tagIds !== 'undefined') {
		    $model->setTagIds(explode(',', $tagIds));
	    }

        $model->saveUploadedFile($routes, $rename);
        $bundle = FilemanagerAsset::register($this->view);

        if ($model->isImage()) {
            $model->createThumbs($routes, $this->module->thumbs);
        }

        $response['files'][] = [
            'url'           => $model->url,
            'thumbnailUrl'  => $model->getDefaultThumbUrl($bundle->baseUrl),
            'name'          => $model->filename,
            'type'          => $model->type,
            'size'          => $model->file->size,
            'deleteUrl'     => Url::to(['file/delete', 'id' => $model->id]),
            'deleteType'    => 'POST',
        ];

        return $response;
    }
201081
protected function handleThumb()
    {
        if ($this->thumbId !== $this->content->thumb_id) {
            if ($this->thumbId === null) {
                return $this->content->thumb()->dissociate();
            }

            $thumb = File::find($this->thumbId);
            if (empty($thumb)) {
                throw new InvalidArgumentException('Thumbnail file does not exist');
            }
            return $this->content->thumb()->associate($thumb);
        }
    }
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;
    }