如何使用ThinkPHP生成缩略图(thinkphp,开发技术)

时间:2024-04-30 00:06:13 作者 : 石家庄SEO 分类 : 开发技术
  • TAG :

首先了解父类Image.class.php(ThinkPHP/Library/Think/Image.class.php)中的一些函数

1:open() 打开被处理的图片

2:thumb() 生成缩略图 默认1等比缩放 (其中2,3,4,5,6代表的含义参见父类文件Image.class.php)

3:save() 缩略图到服务器

生成缩略图步骤分以下四步

* 1.实例化
* 2.打开图片open()
* 3.生成缩略图thumb() 默认等比缩放
* 4.保存save()

控制器代码:

//大图路径(此处大图路径可参考上篇“使用ThinkPHP实现附件上传”的上传路径)$bigimg_path=$upload->rootPath.$file_info['savepath'].$file_info['savename'];//小图路径$smallimg_path=$upload->rootPath.$file_info['savepath'].'small_'.$file_info['savename'];$img=new\Think\Image();//实例化$img->open($bigimg_path);//打开被处理的图片$img->thumb(100,100);//制作缩略图(100*100)$img->save($smallimg_path);//保存缩略图到服务器//把上传好的附件及缩略图存到数据库$_POST['goods_big_img']=$bigimg_path;$_POST['goods_small_img']=$smallimg_path;

入口文件设置常量

为前台显示缩略图路径方便,在入口文件index.php设置常量,表示站点路径,和数据库存放的图片路径拼接

define('SITE_URL', 'http://www.tp.com/TP/shop/');

前台显示大图及缩略图

<td><!--大图--><imgsrc="<{$smarty.const.SITE_URL}><{$v.goods_big_img}>"height="60"width="60"></td><td><!--小图--><imgsrc="<{$smarty.const.SITE_URL}><{$v.goods_small_img}>"height="40"width="40"></td>

结果

数据库里存放路径

如何使用ThinkPHP生成缩略图

图片

如何使用ThinkPHP生成缩略图

前台显示

如何使用ThinkPHP生成缩略图

 </div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
本文:如何使用ThinkPHP生成缩略图的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:PHP如何实现网页内容html标签补全和过滤下一篇:

3 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18