php 裁剪图片、缩放图片的函数示例
内容摘要
这篇文章主要为大家详细介绍了php 裁剪图片、缩放图片的函数示例,具有一定的参考价值,可以用来参考一下。
面向php教程编程,下面跟随php教程的小编来举个例子吧。经测试代码如
面向php教程编程,下面跟随php教程的小编来举个例子吧。经测试代码如
文章正文
这篇文章主要为大家详细介绍了php 裁剪图片、缩放图片的函数示例,具有一定的参考价值,可以用来参考一下。
面向php教程编程,下面跟随php教程的小编来举个例子吧。经测试代码如下: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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | <code class = "php" > /** * 裁剪、缩放图片 * * @author php教程 www.idcnote.com * @param string $src_image 原始图 * @param string $dst_path 裁剪后的图片保存路径 * @param int $dst_x 新图坐标x * @param int $dst_y 新图坐标y * @param int $src_x 原图坐标x * @param int $src_y 原图坐标y * @param int $dst_w 新图宽度 * @param int $dst_h 新图高度 * @param int $src_w 原图宽度 * @param int $src_h 原图高度 */ function imageCropAndResize( $src_image , $dst_path , $dst_x , $dst_y , $src_x , $src_y , $dst_w , $dst_h , $src_w , $src_h ) { if (function_exists( 'imagecreatefromstring' )) { $src_img = imagecreatefromstring( file_get_contents ( $src_image )); } else { return false; } if (function_exists( 'imagecopyresampled' )) { $new_img = imagecreatetruecolor( $dst_w , $dst_h ); imagecopyresampled( $new_img , $src_img , $dst_x , $dst_y , $src_x , $src_y , $dst_w , $dst_h , $src_w , $src_h ); } elseif (function_exists( 'imagecopyresized' )) { $new_img = imagecreate( $dst_w , $dst_h ); imagecopyresized( $new_img , $src_img , $dst_x , $dst_y , $src_x , $src_y , $dst_w , $dst_h , $src_w , $src_h ); } else { return false; } switch (getFileSuffix( $dst_path )) { case 'png' : if (function_exists( 'imagepng' ) && imagepng( $new_img , $dst_path )) { ImageDestroy( $new_img ); return true; } else { return false; } break ; case 'jpg' : default : if (function_exists( 'imagejpeg' ) && imagejpeg( $new_img , $dst_path )) { ImageDestroy( $new_img ); return true; } else { return false; } break ; case 'gif' : if (function_exists( 'imagegif' ) && imagegif( $new_img , $dst_path )) { ImageDestroy( $new_img ); return true; } else { return false; } break ; } } </code> |
注:关于php 裁剪图片、缩放图片的函数示例的内容就先介绍到这里,更多相关文章的可以留意
代码注释