php生成图片缩略图的方法

yipeiwu_com6年前PHP代码库

本文实例讲述了php生成图片缩略图的方法。分享给大家供大家参考。具体如下:

这里需要用到GD2 library

function make_thumb($src,$dest,$desired_width)
{
 
  /* read the source image */
  $source_image = imagecreatefromjpeg($src);
  $width = imagesx($source_image);
  $height = imagesy($source_image);
  /* find the "desired height" of this thumbnail, relative to the desired width */
  $desired_height = floor($height*($desired_width/$width));
  /* create a new, "virtual" image */
  $virtual_image = imagecreatetruecolor($desired_width,$desired_height);
  /* copy source image at a resized size */
  imagecopyresized($virtual_image,$source_image,0,0,0,0,$desired_width,$desired_height,$width,$height);
  /* create the physical thumbnail image to its destination */
  imagejpeg($virtual_image,$dest, 83);
}

希望本文所述对大家的php程序设计有所帮助。

相关文章

PHP实现限制IP访问的方法

本文实例讲述了PHP实现限制IP访问的方法。分享给大家供大家参考,具体如下: //获取客户端ip if (getenv("HTTP_CLIENT_IP")) $ip = gete...

php获取从百度、谷歌等搜索引擎进入网站关键词的方法

本文实例讲述了php获取从百度、谷歌等搜索引擎进入网站关键词的方法。分享给大家供大家参考。具体实现方法如下: <?php function search_word_fr...

php使用parse_str实现查询字符串解析到变量中的方法

本文实例讲述了php使用parse_str实现查询字符串解析到变量中的方法。分享给大家供大家参考,具体如下: parse_str()函数可实现把字符串解析到变量中,这意味着实现了字符串与...

浅析51个PHP处理字符串的函数

包括,计算字符串长度、分割字符串、查找字符串等等各个方面。1.AddSlashes: 字符串加入斜线。 2.bin2hex: 二进位转成十六进位。 3.Chop: 去除连续空白。 4.C...

PHP4和PHP5共存于一系统

PHP4和PHP5共存于一系统˂!-- google 的广告条 2005年09月20日换位置 唉,22号被停了.郁闷,没作弊呀 11.27日重开了 ˂!-- googl...