打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
解决无论图片大小都会生成缩略图的问题修改
function Thumb($source, $target, $thumbwidth, $thumbheight, $thumbtype = 1, $nosuffix = 0) {
                $return = $this->init('thumb', $source, $target, $nosuffix);
                if($return <= 0) {
                        return $this->returncode($return);
                }

                if($this->imginfo['animated']) {
                        return $this->returncode(0);
                }
                $this->param['thumbwidth'] = intval($thumbwidth);
                if(!$thumbheight || $thumbheight > $this->imginfo['height']) {
                        $thumbheight = $thumbwidth > $this->imginfo['width'] ? $this->imginfo['height'] : $this->imginfo['height']*($thumbwidth/$this->imginfo['width']);
                }
//在这里重新定义的 $thumbheight 的值,只要缩略图的高度大于图片的高度,就对他进行了重新定义。那么我们看看他是怎么重新定义的。
条件:缩略图的高度大于图片的高度


定义条件:
1.如果缩略图的宽度大于图片的宽度,缩略图的高度就等于图片的高度。
(导致结果:本来缩略图的宽度大于图片的宽度,就有可能不需要生成缩略图,但这里人为的使缩略图的高度=图片的高度,因此满足生成缩略图的条件。)
2.如果缩略图的宽度小于图片的宽度,缩略图的高度=图片的高度*缩略图的宽度/图片的宽度(因为缩略图的宽度小于图片的宽度为前提,固此值小于1
因此缩略图的高度会小于图片的高度
(导致结果:缩略图的宽度小于图片的宽度,就应该生成缩略图,无论高度如何。)


所以会产生,无论图片大小,都会生成缩略图。


                $this->param['thumbheight'] = intval($thumbheight);
                $this->param['thumbtype'] = $thumbtype;
                if($thumbwidth < 100 && $thumbheight < 100) {
                        $this->param['thumbquality'] = 100;
                }

                $return = !$this->libmethod ? $this->Thumb_GD() : $this->Thumb_IM();
                $return = !$nosuffix ? $return : 0;

                return $this->sleep($return);
        }



执行函数

function Thumb_GD() {
                if(!function_exists('imagecreatetruecolor') || !function_exists('imagecopyresampled') || !function_exists('imagejpeg') || !function_exists('imagecopymerge')) {
                        return -4;
                }

                $imagefunc = &$this->imagefunc;
                $attach_photo = $this->loadsource();
                if($attach_photo < 0) {
                        return $attach_photo;
                }
                $copy_photo = imagecreatetruecolor($this->imginfo['width'], $this->imginfo['height']);
                imagecopy($copy_photo, $attach_photo ,0, 0, 0, 0, $this->imginfo['width'], $this->imginfo['height']);
                $attach_photo = $copy_photo;

                $thumb_photo = null;
                switch($this->param['thumbtype']) {
                        case 'fixnone':
                        case 1:
                                if($this->imginfo['width'] >= $this->param['thumbwidth'] || $this->imginfo['height'] >= $this->param['thumbheight']) {
                                        $thumb = array();
                                        list(,,$thumb['width'], $thumb['height']) = $this->sizevalue(0);
                                        $cx = $this->imginfo['width'];
                                        $cy = $this->imginfo['height'];
                                        $thumb_photo = imagecreatetruecolor($thumb['width'], $thumb['height']);
                                        imagecopyresampled($thumb_photo, $attach_photo ,0, 0, 0, 0, $thumb['width'], $thumb['height'], $cx, $cy);
                                }
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
图片剪裁并生算法
玛瑙原石
即刻图片 银元图片及价格
卡通狗图片
Thinkphp生成缩略图方法
DZX系列里有关贴内图片显示宽度的后台设置
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服