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封装的非对称加密RSA算法示例

本文实例讲述了PHP封装的非对称加密RSA算法。分享给大家供大家参考,具体如下: 将php的openssl扩展中的非对称加密函数封装成一个Rsa类。 需要注意的是,在windows上,需...

php中ltrim()、rtrim()与trim()删除字符空格实例

本文实例讲述了php中ltrim()、rtrim()与trim()删除字符空格的方法。分享给大家供大家参考。具体分析如下: php中的trim函数不能像asp中的一样,可以自动删除所有空...

PHP实现的只保留字符串首尾字符功能示例【隐藏部分字符串】

PHP实现的只保留字符串首尾字符功能示例【隐藏部分字符串】

本文实例讲述了PHP实现的只保留字符串首尾字符功能。分享给大家供大家参考,具体如下: 整理提供两个PHP函数,用于字符串的隐藏效果 ①. 隐藏部分字符串 /** * 隐藏部分字符串...

Yii中render和renderPartial的区别

以下由我们在信易网络公司开发项目的时候终结出的一些经验 在进行页面输出渲染的时候。 1.render 输出父模板的内容,将渲染的内容,嵌入父模板。| 2.renderPartial 则不...

深入讲解PHP Session及如何保持其不过期的方法

SESSION的实现中采用COOKIE技术,SESSION会在客户端保存一个包含session_id(SESSION编号)的COOKIE;在服务器端保存其他session变量,比如ses...