一:安装intervention/image拓展
二:上传文件
\Intervention\Image\ImageManagerStatic::make($_FILES['file']['tmp_name'])->save('upload.jpg');//file为上传表单的name名
\Intervention\Image\ImageManagerStatic::make($_FILES['file']['tmp_name'])->resize(300, 200)->save('upload.jpg');//file为上传表单的name名,并将上传的图片压缩成300,200
if ($_FILES['file']) {
$image = $_FILES['file']['tmp_name'];
if (is_array($image)) {
//多图上传
foreach ($image as $key => $item) {
\Intervention\Image\ImageManagerStatic::make($item)->save($key.'upload.jpg');
}
} else {
//单图上传
\Intervention\Image\ImageManagerStatic::make($image)->save('upload.jpg');
}
}三:添加水印
关闭字体对象的回调,回调可配置:
(5)valign:配置是垂直对齐方式
(6)angle:配置水印旋转角度
例:
//水印
ImageManagerStatic::make('upload.jpg')->text('水印文字',20,30,function($font){
//配置水印字体
$font->file(\Yii::getAlias('@webroot') . '/simsun.ttc');
//配置水印大小
$font->size(30);
//配置水印颜色
$font->color('#fff');
//配置水印水平居左( left, right and center)
$font->align('left');
//配置水印垂直居下(top, bottom and middle)
$font->valign('bottom');
//配置水印旋转角度
$font->angle(45);
})->save('uploadWater.jpg');
(2)top
(3)top-right
(4)left
(5)center
(6)right
(7)bottom-left
(8)bottom
(9)bottom-right
ImageManagerStatic::make('upload.jpg')->insert('water.jpg','bottom-left',10,10)->save('uploadWater.jpg');http://image.intervention.io/总结