public function testImageView() { $imageView = new Qiniu_ImageView(); $imageView->Mode = 1; $imageView->Width = 80; $imageView->Format = 'jpg'; $url = $this->url; $expectedUrl = $url . '?imageView/1/w/80/format/jpg'; $this->assertEquals($imageView->MakeRequest($url), $expectedUrl); }
/** * 获取缩略图地址 * @param type $qiniuFileName 已经存在的文件名 * @param type $width 宽度 * @param type $height 高度 */ public function getThumb($qiniuFileName, $width, $height) { require_once 'qiniu/fop.php'; $key1 = $qiniuFileName; $domain = 'zhaoliwu.qiniudn.com'; //$baseUrl 就是您要访问资源的地址 $baseUrl = Qiniu_RS_MakeBaseUrl($domain, $key1); // $getPolicy = new Qiniu_RS_GetPolicy(); $imgView = new Qiniu_ImageView(); $imgView->Mode = 1; $imgView->Width = $width; $imgView->Height = $height; //生成fopUrl $imgViewUrl = $imgView->MakeRequest($baseUrl); return $imgViewUrl; //对fopUrl 进行签名,生成privateUrl。 公有bucket 此步可以省去。 // $imgViewPrivateUrl = $getPolicy->MakeRequest($imgViewUrl, null); // echo "\n\n====> imageView privateUrl: \n"; // echo $imgViewPrivateUrl . "\n"; }
public function getImageView($mode = 0, $width = '', $height = '', $format = '', $interlace = '') { require_once LIBPATH . 'Qiniu/rs.php'; require_once LIBPATH . 'Qiniu/fop.php'; $domain = $this->bucket . '.qiniudn.com'; Qiniu_SetKeys($this->accessKey, $this->secretKey); //生成baseUrl $baseUrl = Qiniu_RS_MakeBaseUrl($domain, $filename); //生成fopUrl $imgView = new Qiniu_ImageView(); $imgView->Mode = $mode; $imgView->Width = $width; $imgView->Height = $height; $imgView->Format = $format; $imgView->Interlace = $interlace; $imgViewUrl = $imgView->MakeRequest(); //对fopUrl 进行签名,生成privateUrl。 公有bucket 此步可以省去。 // $getPolicy = new Qiniu_RS_GetPolicy(); // return $getPolicy->MakeRequest($imgViewUrl, null); return $imgViewUrl; }
public function imageThumb($filename, $mode, $width, $height) { $this->setBucketAndKey($filename); Qiniu_SetKeys($this->accessKey, $this->secretKey); $domain = $this->getDomain(); $baseUrl = Qiniu_RS_MakeBaseUrl($domain, $this->key); $imgView = new \Qiniu_ImageView(); $imgView->Mode = $mode; $imgView->Width = $width; $imgView->Height = $height; $imgViewUrl = $imgView->MakeRequest($baseUrl); return $imgViewUrl; }
$imgInfo = new Qiniu_ImageInfo(); //生成fopUrl $imgInfoUrl = $imgInfo->MakeRequest($baseUrl); //对fopUrl 进行签名,生成privateUrl。 公有bucket 此步可以省去。 $imgInfoPrivateUrl = $getPolicy->MakeRequest($imgInfoUrl, null); echo "\n\n====> imageInfo privateUrl: \n"; echo $imgInfoPrivateUrl . "\n"; # @endgist # @gist image_exif $getPolicy = new Qiniu_RS_GetPolicy(); $imgExif = new Qiniu_Exif(); //生成fopUrl $imgExifUrl = $imgExif->MakeRequest($baseUrl); //对fopUrl 进行签名,生成privateUrl。 公有bucket 此步可以省去。 $imgExifPrivateUrl = $getPolicy->MakeRequest($imgExifUrl, null); echo "\n\n====> imageView privateUrl: \n"; echo $imgExifPrivateUrl . "\n"; # @endgist # @gist image_view $getPolicy = new Qiniu_RS_GetPolicy(); $imgView = new Qiniu_ImageView(); $imgView->Mode = 1; $imgView->Width = 60; $imgView->Height = 30; //生成fopUrl $imgViewUrl = $imgView->MakeRequest($baseUrl); //对fopUrl 进行签名,生成privateUrl。 公有bucket 此步可以省去。 $imgViewPrivateUrl = $getPolicy->MakeRequest($imgViewUrl, null); echo "\n\n====> imageView privateUrl: \n"; echo $imgViewPrivateUrl . "\n"; # @endgist
function picThumb($accessKey, $secretKey, $key1, $width, $height) { // --------------------------压缩图片 start // require_once('qiniu/rs.php'); require_once 'qiniu/fop.php'; $key1 = $key1; $domain = 'zhaoliwu.qiniudn.com'; Qiniu_setKeys($accessKey, $secretKey); //$baseUrl 就是您要访问资源的地址 $baseUrl = Qiniu_RS_MakeBaseUrl($domain, $key1); $getPolicy = new Qiniu_RS_GetPolicy(); $imgView = new Qiniu_ImageView(); $imgView->Mode = 1; $imgView->Width = $width; $imgView->Height = $height; //生成fopUrl $imgViewUrl = $imgView->MakeRequest($baseUrl); //对fopUrl 进行签名,生成privateUrl。 公有bucket 此步可以省去。 $imgViewPrivateUrl = $getPolicy->MakeRequest($imgViewUrl, null); echo "\n\n====> imageView privateUrl: \n"; echo $imgViewPrivateUrl . "\n"; // ------------------------------------ end }
public function getThumb($path, $width, $height, $original) { global $_G; $client = self::init($path, 1); $arr = self::parsePath($path); if ($original) { $imgurl = self::getFileUri($path); $imginfo = @getimagesize($imgurl); @header("Content-Type: " . image_type_to_mime_type($imginfo[2])); @ob_end_clean(); if (getglobal('gzipcompress')) { @ob_start('ob_gzhandler'); } @readfile($imgurl); @flush(); @ob_flush(); exit; } $imgcachePath = './imgcache/'; $cachepath = str_replace(':', '/', $path); $target = $imgcachePath . $cachepath . '.' . $width . '_' . $height . '.jpeg'; if ($imginfo = @getimagesize($_G['setting']['attachdir'] . $target)) { @header("Content-Type: " . image_type_to_mime_type($imginfo[2])); @ob_end_clean(); if (getglobal('gzipcompress')) { @ob_start('ob_gzhandler'); } @readfile($_G['setting']['attachdir'] . $target); @flush(); @ob_flush(); exit; } $targetpath = dirname($_G['setting']['attachdir'] . $target); dmkdir($targetpath); //获取缩略图保存到本地 $getPolicy = new Qiniu_RS_GetPolicy(); $imgView = new Qiniu_ImageView(); $imgView->Mode = 2; $imgView->Width = $width; $imgView->Height = $height; $baseUrl = Qiniu_RS_MakeBaseUrl($this->_domain, $arr['object']); //生成fopUrl $imgViewUrl = $imgView->MakeRequest($baseUrl); //对fopUrl 进行签名,生成privateUrl。 公有bucket 此步可以省去。 $imgViewPrivateUrl = $getPolicy->MakeRequest($imgViewUrl, null); @file_put_contents($_G['setting']['attachdir'] . $target, fopen($imgViewPrivateUrl, 'rb')); if ($imginfo = @getimagesize($_G['setting']['attachdir'] . $target)) { @header("Content-Type: " . image_type_to_mime_type($imginfo[2])); @ob_end_clean(); if (getglobal('gzipcompress')) { @ob_start('ob_gzhandler'); } @readfile($_G['setting']['attachdir'] . $target); @flush(); @ob_flush(); exit; } else { @header("Location:{$imgViewPrivateUrl}"); exit; } }