找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1904|回复: 0
打印 上一主题 下一主题

php使用GD创建保持宽高比缩略图的方法

[复制链接]

2647

主题

2647

帖子

7881

积分

论坛元老

Rank: 8Rank: 8

积分
7881
跳转到指定楼层
楼主
发表于 2018-2-14 05:46:45 | 只看该作者 回帖奖励 |正序浏览 |阅读模式

            本文实例讲述了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绘制基本图形示例(直线、圆、正方形)
            
  • 分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    用户反馈
    客户端