此代码可以为大图片动态生成缩略图显示,图片在内存中生成,不在硬盘生成真实文件,php动态生成缩略图输出显示,感兴趣的小伙伴,下面一起跟随编程之家 jb51.cc的小编来看看吧。
经测试代码如下:
/**
* 动态生成缩略图输出显示
*
* @Example: <img src=thumbs.php?filename=photo.jpg&width=100&height=100>
* @arrange (编程之家) jb51.cc
**/
$filename= $_GET['filename'];
$width = $_GET['width'];
$height = $_GET['height'];
$path=http://localhost/images/; //finish in /
// Content type
header('Content-type: image/jpeg');
// Get new dimensions
list($width_orig,$height_orig) = getimagesize($path.$filename);
if ($width && ($width_orig < $height_orig)) {
$width = ($height / $height_orig) * $width_orig;
} else {
$height = ($width / $width_orig) * $height_orig;
}
// Resample
$image_p = imagecreatetruecolor($width,$height);
$image = imagecreatefromjpeg($path.$filename);
imagecopyresampled($image_p,$image,$width,$height,$width_orig,$height_orig);
// Output
imagejpeg($image_p,null,100);
// Imagedestroy
imagedestroy ($image_p);
?>
/*** 来自编程之家 jb51.cc(jb51.cc) ***/
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。