tp-上传图片,自带截取图片
2015-12-22 15:51
671 查看
是tp自带的,然后包括截取图片,开发手册都有。这里是生成一张原图、一张截图。只是我返回的是原图。截图后有后缀名。
下面返回的是已经截好的图。
/*图片上传*/ public function upload2(){ $file = $_FILES['file']; $upload = new \Think\Upload();// 实例化上传类 $upload->maxSize = 2*1024*1024; $upload->rootPath = './Uploads/'; // 设置附件上传根目录 $upload->savePath = 'Home/lpq/'; // 设置附件上传(子)目录 $info = $upload->uploadOne($file); /* --- 从这里开始做截图图片 start ---*/ $infourl= './Uploads/'.$info['savepath'].$info['savename']; $image = new \Think\Image(); $image->open($infourl);//将图片裁剪为400x400并保存为corp.jpg $width = $image->width(); // 返回图片的宽度 $height = $image->height(); // 返回图片的高度 $newUrl = str_replace('.'.$info['ext'],'',$infourl).'_t.'.$info['ext']; $iw = 320; $ih = 345; $image->thumb($iw, $ih,\Think\Image::IMAGE_THUMB_CENTER)->save($newUrl); /* --- 从这里开始做截图图片 end ---*/ exit(json_encode($info)); }
下面返回的是已经截好的图。
/*图片上传*/ public function upload2(){ $file = $_FILES['file']; $upload = new \Think\Upload();// 实例化上传类 $upload->maxSize = 2*1024*1024; $upload->rootPath = './Uploads/'; // 设置附件上传根目录 $upload->savePath = 'Home/lpq/'; // 设置附件上传(子)目录 $info = $upload->uploadOne($file); /*--- 这里返回的是已经截好的图了。start --- */ $infourl='./Uploads/'.$info['savepath'].$info['savename']; $image = new \Think\Image(); $image->open($infourl);//将图片裁剪为400x400并保存为corp.jpg $width = $image->width(); // 返回图片的宽度 $height = $image->height(); // 返回图片的高度 $iw = $ih = 300; if($iw>$width){ $iw = $width; } if($ih>$height){ $ih = $height; } if($width>300 || $height>300){ $image->thumb($iw, $ih,\Think\Image::IMAGE_THUMB_CENTER)->save($infourl); } exit(json_encode($info)); /*--- 这里返回的是已经截好的图了。end--- */ }
相关文章推荐
- PHP soap 调用 JAVA发布的webservice
- PHP 5.6启动失败failed to open configuration file '/usr/local/php/etc/php-fpm.conf'
- php通过循环链解决约瑟夫环
- AJAX跨域访问PHP的设置
- PHP 中的随机数——你觉得可靠么?
- php 下 POST方法提交参数丢失问题
- PHP 中的随机数——你觉得可靠么?
- PHP--时区配置
- 配置eAccelerator和XCache扩展来加速PHP程序的执行
- Thinkphp编辑器扩展类kindeditor用法
- PHP中使用RSA加密总结
- PHP socket类
- php获取字符串拼音和拼音首字母
- 学PHP避免即将到来的就业危机
- PHP学习的一种习惯
- PHPCMS 实现上一篇、下一篇
- Yii框架操作数据库的几种方式与mysql_escape_string
- 在windows下ftp服务器上传文件错误
- 如果ftp服务器使用windows下IIS创建,通过资源管理器登陆ftp服务器,输入正确的用户名和密码,点击登陆按钮没有反应
- php验证是否为非零整数(正整数、负整数)