namespace Home\Controller;
include_once './vendor/autoload.php';
use Think\Controller;
use Intervention\Image\ImageManagerStatic as Image;
use Intervention\Image\ImageManager as ImageManager;
class ApiImageController extends Controller
{
private $image_cache_lifetime = 864000;
private $response_image_type = 'jpg';//相应图片的类型(自动转换)
private $image_quality = 95;//图片质量
private $path;//要缩放的图片路径
private $width = 200;//缩略图宽度
private $height;//缩略图高度,默认不指定
//缩略图位置,可选值: top-left top top-right left center right bottom-left bottom bottom-right
private $pos = 'center';
public function __construct()
{
parent::__construct();
$this->path = I('path');
if (!$this->path) {
echo 'path invalid';
die;
//$this->response_json('error', '参数有误');
}
//宽度
if ($width = intval(I('w'))) {//高度
$this->width = $width;
}
//高度
if ($height = I('h')) {
$this->height = $height;
}
//质量
if ($quality = intval(I('q'))) {
$this->image_quality = $quality;
}
//位置
if ($pos = I('pos')) {
$this->pos = $pos;
}
Image::configure(
array(
'driver' => 'gd',
'cache' => array(
//'encoded'=>false,
'path' => '/tmp/thd_image'//临时文件路径
)
)
);
}
/**
* 图片缩略-不带缓存
*/
public function thumb1(){
$ImageManager = new ImageManager(array('driver'=>'gd'));
$file = './'.$this->path;
echo $ImageManager->make($file)->resize($this->width,$this->height)->response();
}
} 最佳答案