用户
 找回密码
 入住 CI 中国社区
搜索
查看: 4528|回复: 3
收起左侧

[已过期] 有完整的CodeIgniter购物车和图片上传生成缩略图实例吗?

[复制链接]
发表于 2010-7-21 16:44:28 | 显示全部楼层 |阅读模式
有完整的CodeIgniter购物车和CodeIgniter图片上传生成缩略图实例吗?
发表于 2010-9-8 06:04:23 | 显示全部楼层
我觉得可以用PHP内置的函数
推荐先获取原图的尺寸。然后按照等比的算式算一下需要的小尺寸
然后用PHP的缩略图函数即可。

这个是我写的一个方法
function make_thumb_img($file_url='',$max_width=0,$max_height=0)
{   
        $ext = strtolower(end(explode('.',$file_url)));         
                if ($ext == 'jpg'|| $ext == 'jpeg') {
             $img = imagecreatefromjpeg($file_url);
                        } else if ($ext == 'png') {
                            $img = imagecreatefrompng($file_url);
                        } else if ($ext == 'gif') {
                            $img = imagecreatefrompng($file_url);
                        }       
                        $width=imagesx($img);
                        $height=imagesy($img);
               
                        if($max_width!=0 && $max_height==0)
                        {
                        $x=$max_width;
                        $y=ceil($x*$height/$width);
                        }
                        else if($max_width==0 && $max_height!=0)
                        {
                                $y=$max_height;
                                $x=ceil($y*$width/$height);
                        }
                       
                        $dst=imagecreatetruecolor($x,$y);
                        imagecopyresampled($dst,$img,0,0,0,0,$x,$y,$width,$height);
                       
            header('Content-type: image/png');
            imagepng($dst);
        }
发表于 2010-9-8 06:34:02 | 显示全部楼层
上面的方法导出的东西可以用<img src="" />
来收
发表于 2011-4-16 22:25:38 | 显示全部楼层
强 学习中

本版积分规则