本文实例讲述了php使用gd创建保持宽高比缩略图的方法。分享给大家供大家参考。具体如下:
/*** create a thumbnail image from $inputfilename no taller or wider than* $maxsize. returns the new image resource or false on error.* author: mthorn.net*/function thumbnail($inputfilename, $maxsize = 100){ $info = getimagesize($inputfilename); $type = isset($info['type']) ? $info['type'] : $info[2]; // check support of file type if ( !(imagetypes() & $type) ) {// server does not support file typereturn false; } $width = isset($info['width']) ? $info['width'] : $info[0]; $height = isset($info['height']) ? $info['height'] : $info[1]; // calculate aspect ratio $wratio = $maxsize / $width; $hratio = $maxsize / $height; // using imagecreatefromstring will automatically detect the file type $sourceimage = imagecreatefromstring(file_get_contents($inputfilename)); // calculate a proportional width and height no larger than the max size. if ( ($width
希望本文所述对大家的php程序设计有所帮助。
,
