php 动态生成缩略图并输出显示的解决办法
内容摘要
这篇文章主要为大家详细介绍了php 动态生成缩略图并输出显示的简单示例,具有一定的参考价值,可以用来参考一下。
调用方法:<img src="thumbs.php?filename=photo.jpg&width=10
调用方法:<img src="thumbs.php?filename=photo.jpg&width=10
文章正文
这篇文章主要为大家详细介绍了php 动态生成缩略图并输出显示的简单示例,具有一定的参考价值,可以用来参考一下。
调用方法:<img src="thumbs.php?filename=photo.jpg&width=100&height=100">此代码可以为大图片动态生成缩略图显示,图片在内存中生成,不在硬盘生成真实文件,php动态生成缩略图输出显示,对此感兴趣的朋友,看看idc笔记做的技术笔记。经测试代码如下:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | <code class = "php" > /** * 动态生成缩略图输出显示 * * @Example: <img src="thumbs.php?filename=photo.jpg&width=100&height=100"> * @arrange (www.idcnote.com) **/ $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 , 0, 0, 0, 0, $width , $height , $width_orig , $height_orig ); // Output imagejpeg( $image_p , null, 100); // Imagedestroy imagedestroy ( $image_p ); ?> /*** 来自php教程(www.idcnote.com) ***/ </code> |
注:关于php 动态生成缩略图并输出显示的简单示例的内容就先介绍到这里,更多相关文章的可以留意
代码注释