PHP生成缩略图实例讲解
封装的方法函数:
=$scale){
//创建真彩图像资源(imagecreatetruecolor()函数使用GDLibrary创建新的真彩色图像)
$newimg=imagecreatetruecolor($thumbWidth,$thumbHeight);
//图像处理
imagecopyresampled($newimg,$sourceImg,0,0,0,0,$thumbWidth,$thumbHeight,(($height)*$scale),$height);
//以JPEG格式将图像输出到浏览器或文件
ImageJpeg($newimg,$thumbSrc);
}
//宽度优先
if($ratio<$scale){
$newimg=imagecreatetruecolor($thumbWidth,$thumbHeight);
imagecopyresampled($newimg,$sourceImg,0,0,0,0,$thumbWidth,$thumbHeight,$width,(($width)/$scale));
ImageJpeg($newimg,$thumbSrc);
}
}else{
if($ratio>=$scale){
$newimg=imagecreatetruecolor($thumbWidth,($thumbWidth)/$ratio);
imagecopyresampled($newimg,$sourceImg,0,0,0,0,$thumbWidth,($thumbWidth)/$ratio,$width,$height);
ImageJpeg($newimg,$thumbSrc);
}
if($ratio<$scale){
$newimg=imagecreatetruecolor(($thumbHeight)*$ratio,$thumbHeight);
imagecopyresampled($newimg,$sourceImg,0,0,0,0,($thumbHeight)*$ratio,$thumbHeight,$width,$height);
ImageJpeg($newimg,$thumbSrc);
}
}
//销毁图像
ImageDestroy($sourceImg);
}
?>
调用示例:
到此这篇关于PHP生成缩略图实例讲解的文章就介绍到这了,更多相关PHP生成缩略图内容请搜索毛票票以前的文章或继续浏览下面的相关文章希望大家以后多多支持毛票票!
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。