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

相关文章

WordPress开发中自定义菜单的相关PHP函数使用简介

函数意义 wp_nav_menu () 自定义菜单显示函数 register_nav_menu () 自定义菜单注册函数 – 单数 register_nav_menus () 自定义菜单...

php中将网址转换为超链接的函数

复制代码 代码如下: function showtext($text){ $search = array('|(http://[^ ]+)|', '|(https://[^ ]+)|',...

PHP CURL使用详解

PHP CURL是一个非常强大的开源库,支持很多协议,包括HTTP、FTP、TELNET等,我们使用它来发送HTTP请求。它给我们带来的好处是可以通过灵活的选项设置不同的HTTP协议参数...

php5对象复制、clone、浅复制与深复制实例详解

本文实例讲述了php5对象复制、clone、浅复制与深复制。分享给大家供大家参考,具体如下: 对象复制的由来 为什么对象会有“复制”这个概念,这与PHP5中对象的传值方式是密切相关的,让...

PHP 开发环境配置(Zend Studio)

PHP 开发环境配置(Zend Studio)

  安装完成后运行程序 在Help菜单中有Register选项进行注册。 提供注册码如下: Username: zendstudio.netSerial Nu...