php使用GD创建保持宽高比缩略图的方法,phpgd缩略图_PHP教程
程序员文章站
2022-06-12 21:45:56
...
php使用GD创建保持宽高比缩略图的方法,phpgd缩略图
本文实例讲述了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 type return 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程序设计有所帮助。