TP3.2:上传预览+缩略图+水印实例
程序员文章站
2022-05-19 19:01:46
...
uploadify上传预览+缩略图+水印实例
首先感谢各位大神网友的分享,我只是改改代码,让其更符合自己的业务逻辑
图片上传+缩略图+水印处理代码:
首先感谢各位大神网友的分享,我只是改改代码,让其更符合自己的业务逻辑
图片上传+缩略图+水印处理代码:
//文件上传
Public function _upload( $thumb = false , $thumbWidth = '' , $thumbHeight = '') {
$upload = new \Think\Upload();// 实例化上传类
$upload->maxSize = 3145728 ;// 设置附件上传大小
$upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
$upload->savePath = '/' . CONTROLLER_NAME .'/'; // 设置附件上传目录
$info = $upload->upload();
if(!$info) {
return array('status' =>0, 'info'=> $upload->getError() );
}else{
if( $thumb ) { //生成缩略图
$image = new \Think\Image();
foreach($info as $file) {
$thumb_file = './Uploads/' . $file['savepath'] . $file['savename'];
$save_path = './Uploads/' .$file['savepath'] . 'mini_' . $file['savename'];
$image->open( $thumb_file )->text('德兴房产','./data/1.otf',30,'#A7AAA4',\Think\Image::IMAGE_WATER_SOUTHWEST)->save( $thumb_file );
$image->open( $thumb_file )->text('德兴房产','./data/1.otf',24,'#A7AAA4',\Think\Image::IMAGE_WATER_SOUTHWEST)->thumb( $thumbWidth, $thumbHeight )->save( $save_path );
return array(
'status' => 1,
'savepath' => $file['savepath'],
'savename' => $file['savename'],
'pic_path' => $file['savepath'] . $file['savename'],
'mini_pic' => $file['savepath'] . 'mini_' .$file['savename']
);
}
}else{
foreach($info as $file) {
return array(
'status' => 1,
'savepath' => $file['savepath'],
'savename' => $file['savename'],
'pic_path' => $file['savepath'].$file['savename']
);
}
}
}
}
前端主要代码(参考http://www.thinkphp.cn/code/151.html):
推荐阅读