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实现将wav文件转换成图像文件并在页面中显示的方法

php实现将wav文件转换成图像文件并在页面中显示的方法

本文实例讲述了php实现将wav文件转换成图像文件并在页面中显示的方法。分享给大家供大家参考。具体分析如下: 需求:将wav文件转换成png文件并且显示出来。 Wav_To_Png.ph...

PHP XML操作类DOMDocument

DOMDocument相关的内容. 属性: Attributes 存储节点的属性列表(只读) childNodes 存储节点的子节点列表(只读) dataType 返回此节点的数据类型...

PHP使用递归算法无限遍历数组示例

本文实例讲述了PHP使用递归算法无限遍历数组。分享给大家供大家参考,具体如下: (PS:为方便阅读,此处代码使用php代码格式化工具http://tools.jb51.net/code/...

PHP在获取指定目录下的目录,在获取的目录下面再创建文件,多平台

复制代码 代码如下: //取得指定文件夹的目录名称 function get_dir_name($dir_path,$file) { $dirpath = $dir_path; $dir...

PHP实现统计所有字符在字符串中出现次数的方法

PHP实现统计所有字符在字符串中出现次数的方法

本文实例讲述了PHP实现统计所有字符在字符串中出现次数的方法。分享给大家供大家参考,具体如下: 先来看看效果: 算法: 循环一次字符串(本例的$str),把出现过的字符串记录在一个数组...