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删除文件夹及其文件夹下所有文件的函数代码

复制代码 代码如下: <? function deldir($dir) { //先删除目录下的文件: $dh=opendir($dir); while ($file=readdir...

PHP 多维数组排序实现代码

array_multisort (PHP 4, PHP 5) array_multisort -- 对多个数组或多维数组进行排序 说明 bool array_multisort ( ar...

Windows下的PHP5.0详解

PHP5包括以下一些重要的特征:    ·支持新的对象模型和许多新特点的Zend引擎。   ·完全重新编写了XML支持,扩展性能围绕着优秀的libxml2库(http://ww...

PHP实现普通hash分布式算法简单示例

本文实例讲述了PHP实现普通hash分布式算法。分享给大家供大家参考,具体如下: <?php /* * 普通hash分布式算法 * @param $key * @...

数组与类使用PHP的可变变量名需要的注意的问题

有时候可变的变量名会给编程带来很大的方便。也就是说变量名可以被动态的命名和使用。通常变量通过下面这样的语句来命名 :$a = 'hello';可变变量名指的是使用一个变量的值作为这个变量...