时时商务社区

标题: php使用GD创建保持宽高比缩略图的方法 [打印本页]

作者: 网络通达    时间: 2018-2-14 05:46

            本文实例讲述了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程序设计有所帮助。
            
            
您可能感兴趣的文章:
  • php中使用gd库实现远程图片下载实例
  • php中使用gd库实现下载网页中所有图片
  • php使用GD实现颜色渐变实例
  • php使用GD库创建图片缩略图的方法
  • PHP中使用GD库绘制折线图 折线统计图的绘制方法
  • php中使用GD库做验证码
  • php gd等比例缩放压缩图片函数
  • PHP基于GD库的图像处理方法小结
  • PHP GD库相关图像生成和处理函数小结
  • php利用gd库为图片添加水印
  • PHP使用GD库输出汉字的方法【测试可用】
  • 如何打开php的gd2库
  • php使用GD2绘制几何图形示例
  • php使用gd2绘制基本图形示例(直线、圆、正方形)
            




    欢迎光临 时时商务社区 (http://bbs.4435.cn/) Powered by Discuz! X3.2