/** * 控制器执行主逻辑函数 * @example URL Structure http://www.miniyun.cn/api/thumbnails/<root>/<path> * @version 0 * @method GET * @param format * <p>JPEG (default) or PNG. For images that are photos, JPEG should be preferred, while PNG is better for screenshots and digital art.</p> * @param size * <p>One of the following values (default small):</p> * <p>value dimensions (px)</p> * <p>small 32x32</p> * <p>medium 64x64</p> * <p>large 128x128</p> * <p>s 64x64</p> * <p>m 128x128</p> * <p>l 640x480</p> * <p>xl 1024x768</p> * @return mixed $value 返回最终需要执行完的结果 */ public function invoke($uri = null) { // 调用父类初始化函数,注册自定义的异常和错误处理逻辑 parent::init(); // 初始化缩略图处理类 $thumbnail_base = MThumbnailBase::initMThumbnailBase($uri); $thumbnail_base->create(); $thumbnail_base->render(); }
/** * 获得缩略图 * @param $key * @param $path * @param $size * @return string */ public function thumbnail($key, $path, $size) { $link = MiniLink::getInstance()->getByKey($key); if ($link !== NULL) { $file = MiniFile::getInstance()->getById($link["file_id"]); $parentPath = $file["file_path"]; if ($file !== NULL) { $userId = $file["user_id"]; $absolutePath = MiniUtil::getAbsolutePath($userId, $path); //必须限定子目录在外链目录下 if (strpos($absolutePath, $parentPath) == 0) { $thumbnail = new MThumbnailBase(); $thumbnail->user_id = $file["user_id"]; $thumbnail->path = $path; $thumbnail->size = $size; $thumbnail->format = "jpg"; $thumbnail->create(); $thumbnail->render(); } } } }