| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 | 
							- <?php
 
- namespace app\api\controller\v1;
 
- use app\hander\HelpHander;
 
- use think\Controller;
 
- use think\Db;
 
- use think\Exception;
 
- class Upload extends Controller
 
- {
 
-     public function upfile(){
 
-         $file = request()->file('uploadFile');
 
-         // 移动到框架应用根目录/uploads/ 目录下
 
-         $info = $file->validate([ 'size'=>config('app.max_upload_file_size') ])
 
-             ->move(env('root_path') . 'public' . DIRECTORY_SEPARATOR . 'uploads'. DIRECTORY_SEPARATOR . 'files');
 
-         if($info){
 
-             $img = '/uploads/files/' . $info->getSaveName();
 
-             $img = str_replace('\\', '/', $img);
 
-             HelpHander::success(['path' => config("app.app_host").$img]);
 
-         }else{
 
-             // 上传失败获取错误信息
 
-             HelpHander::error($file->getError());
 
-         }
 
-     }
 
-     public function upimg(){ // 只能上传规定的图片,添加水印,时间 地点 人物 模块
 
-         $file = request()->file('uploadFile');
 
-         // 移动到框架应用根目录/uploads/ 目录下
 
-         $config = config('max_upload_img');
 
-         $info = $file->validate($config)
 
-             ->move(env('root_path') . 'public' . DIRECTORY_SEPARATOR . 'uploads'. DIRECTORY_SEPARATOR . 'files');
 
-         if($info){
 
-             $img = '/uploads/files/' . $info->getSaveName();
 
-             $img = str_replace('\\', '/', $img);
 
-             try{
 
-                 $this->thumb($img);
 
-                 $image = \think\Image::open('.'.$img);
 
-                 $width = $image->width();
 
-                 $height = $image->height();
 
-                 $size = 100;
 
-                 $curSize = round($size*$width/2000);
 
-                 $h = 100;
 
-                 $curH = round($h*$width/2000);
 
-                 $address = input('address', '', 'trim');
 
-                 $mode = input('mode', '', 'trim');
 
-                 $userId = input('userId/d', 0);
 
-                 $uname = Db::name('user')->where('id', $userId)->value('real_name');
 
-                 $font = env('root_path') . 'public/static/hylht.ttf';
 
-                 $i = 3;
 
-                 if($address){
 
-                     $i = 4;
 
-                 }
 
-                 $arr1 = $this->getSize(date('Y-m-d H:i:s'),$curSize,$width,$height,$i,$curH);
 
-                 $arr2 = $this->getSize($mode,$curSize,$width,$height,$i-1,$curH);
 
-                 if($address){
 
-                     $arr3 = $this->getSize($address,$curSize,$width,$height,2,$curH);
 
-                 }
 
-                 $arr4 = $this->getSize($uname,$curSize,$width,$height,1,$curH);
 
-                 $image->text(date('Y-m-d H:i:s'), $font, $curSize, '#ffffff', $arr1);
 
-                 $image->text($mode, $font, $curSize, '#ffffff', $arr2);
 
-                 if($address){
 
-                     $image->text($address, $font, $curSize, '#ffffff', $arr3);
 
-                 }
 
-                 $image->text($uname, $font, $curSize, '#ffffff', $arr4)->save('.' . $img);
 
-             }catch (\Exception $e){
 
-                 trace('图片上传失败:'.$e->getMessage());
 
-                 HelpHander::error('图片上传失败');
 
-             }
 
-             HelpHander::success(['path' => config("app.app_host").$img]);
 
-         }else{
 
-             // 上传失败获取错误信息
 
-             HelpHander::error($file->getError());
 
-         }
 
-     }
 
-     private function thumb($img){
 
-         $image = \think\Image::open('.'.$img);
 
-         $width = $image->width();
 
-         $height = $image->height();
 
-         if($width > 2000||$height > 2000){
 
-             $image->thumb(2000,2000,\think\Image::THUMB_SCALING)->save('.' . $img);
 
-         }
 
-     }
 
-     private function getSize($text,$size,$weight,$height,$i=1,$ch=100,$angle=0){
 
-         //获取文字信息
 
-         $font = env('root_path').'public/static/hylht.ttf';
 
-         $info = imagettfbbox($size, $angle, $font, $text);
 
-         $minx = min($info[0], $info[2], $info[4], $info[6]);
 
-         $maxx = max($info[0], $info[2], $info[4], $info[6]);
 
-         $miny = min($info[1], $info[3], $info[5], $info[7]);
 
-         $maxy = max($info[1], $info[3], $info[5], $info[7]);
 
-         /* 计算文字初始坐标和尺寸 */
 
-         $x = $minx;
 
-         $y = abs($miny);
 
-         $w = $maxx - $minx;
 
-         $h = $maxy - $miny;
 
-         $xx = ($weight - $w) / 2;
 
-         $yy = $height - ($h+$ch)*$i;
 
-         return [$xx,$yy];
 
-     }
 
-     public function uply(){
 
-         trace($_FILES);
 
-         $file = request()->file('filedata1');
 
-         // 移动到框架应用根目录/uploads/ 目录下
 
-         $info = $file->validate([ 'ext' => 'wav' ])
 
-             ->move(env('root_path') . 'public' . DIRECTORY_SEPARATOR . 'uploads'. DIRECTORY_SEPARATOR . 'luyin');
 
-         if($info){
 
-             $img = '/uploads/luyin/' . $info->getSaveName();
 
-             $img = str_replace('\\', '/', $img);
 
-             $img = config("app.app_host").$img;
 
-             trace($img);
 
-             HelpHander::success(['path' => $img]);
 
-         }else{
 
-             // 上传失败获取错误信息
 
-             HelpHander::error($file->getError());
 
-         }
 
-     }
 
- }
 
 
  |