php生成图片缩略图的方法

yipeiwu_com5年前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简单选择排序算法实例

简单的选择排序算法:通过n-i次关键字间的比较,从n-i+1个记录中选出关键字最小的记录,并和第i(1<=i<=n)个记录交换 复制代码 代码如下: <?php...

php中操作memcached缓存进行增删改查数据的实现代码

核心代码: <?php //创建一个memcache对象实例 $memcache = new Memcache; if(!$memcache->conn...

PHP简单处理表单输入的特殊字符的方法

本文实例讲述了PHP简单处理表单输入的特殊字符的方法。分享给大家供大家参考,具体如下: <html> <body> <?php if...

phpMyAdmin通过密码漏洞留后门文件

phpMyAdmin通过密码漏洞留后门文件

默认 phpMyAdmin:用户名 root 密码 root 或空登陆。 版本 2.11.3~2.11.4:用户名 'localhost'@'@" 登陆,无需密码。 版本...

PHP基于数组实现的分页函数实例

分页功能是PHP程序设计中非常常见的功能,不同于以往的,今天本文介绍的是PHP基于数组实现的分页函数。 关于数组的分页函数,用数组进行分页的好处是可以方便的进行联合多表查询,只需要将查询...