有完整的CodeIgniter购物车和图片上传生成缩略图实例吗?
有完整的CodeIgniter购物车和CodeIgniter图片上传生成缩略图实例吗? 我觉得可以用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);
} 上面的方法导出的东西可以用<img src="" />
来收 强 学习中
页:
[1]