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程序设计有所帮助。

相关文章

Admin generator, filters and I18n

Three easy steps 1) configure function Add an input for each field you want to include in you...

PHP 文件缓存的性能测试

PHP常用缓存方式:第一种,把需要缓存的数据进行处理,形成PHP可以直接执行的文件。在需要缓存数据的时候,通过include方式引入,并使用。第二种,把需要的数据通过serialize函...

php获取文件大小的方法

复制代码 代码如下:static function convert($size) {         $unit=a...

FirePHP 推荐一款PHP调试工具

FirePHP 推荐一款PHP调试工具

PHP调试有很多中方法。今天给大家推荐的是 FirePHP(http://www.firephp.org/)。 这个工具,是基于firefox的一个组件。Firephp组件安装地址。使用...

Apache 配置详解(最好的APACHE配置教程)

Apache的配置 Apache的配置由httpd.conf文件配置,因此下面的配置指令都是在httpd.conf文件中修改。 主站点的配置(基本配置) (1) 基本配置: Serv...