PHP 调整图像尺寸的解决办法
内容摘要
这篇文章主要为大家详细介绍了PHP 调整图像尺寸的简单示例,具有一定的参考价值,可以用来参考一下。
创建图像缩略图需要许多时间,PHP调整图像尺寸,对此感兴趣的朋友,看看idc笔记
创建图像缩略图需要许多时间,PHP调整图像尺寸,对此感兴趣的朋友,看看idc笔记
文章正文
这篇文章主要为大家详细介绍了PHP 调整图像尺寸的简单示例,具有一定的参考价值,可以用来参考一下。
创建图像缩略图需要许多时间,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 | <code class = "php" > /********************** *@filename - path to the image *@tmpname - temporary path to thumbnail *@xmax - max width *@ymax - max height * PHP调整图像尺寸 * @author php教程 www.idcnote.com **/ function resize_image( $filename , $tmpname , $xmax , $ymax ) { $ext = explode ( "." , $filename ); $ext = $ext [ count ( $ext )-1]; if ( $ext == "jpg" || $ext == "jpeg" ) $im = imagecreatefromjpeg( $tmpname ); elseif ( $ext == "png" ) $im = imagecreatefrompng( $tmpname ); elseif ( $ext == "gif" ) $im = imagecreatefromgif( $tmpname ); $x = imagesx( $im ); $y = imagesy( $im ); if ( $x <= $xmax && $y <= $ymax ) return $im ; if ( $x >= $y ) { $newx = $xmax ; $newy = $newx * $y / $x ; } else { $newy = $ymax ; $newx = $x / $y * $newy ; } $im2 = imagecreatetruecolor( $newx , $newy ); imagecopyresized( $im2 , $im , 0, 0, 0, 0, floor ( $newx ), floor ( $newy ), $x , $y ); return $im2 ; } /*** 来自php教程(www.idcnote.com) ***/ </code> |
注:关于PHP 调整图像尺寸的简单示例的内容就先介绍到这里,更多相关文章的可以留意
代码注释