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,js双版本

废话不多说直接上代码。 PHP FOR Smarty 复制代码 代码如下: * Name: time_ago * Purpose: 将时间戳专为距当前时间的表现形式 * 1分钟内按秒 *...

php usort 使用用户自定义的比较函数对二维数组中的值进行排序

今天发现一个很好用二维数组排序的php方法,usort,推荐给大家,以后二维数组里面,要按照一个字段的值排序用这个方法简单高效,例如下面的数组: [guess_subject] =&...

PHP 地址栏信息的获取代码

复制代码 代码如下:<?php //获取域名或主机地址 echo $_SERVER['HTTP_HOST']."<br>"; //获取网页地址 echo $_SERVE...

thinkPHP5实现的查询数据库并返回json数据实例

本文实例讲述了thinkPHP5实现的查询数据库并返回json数据。分享给大家供大家参考,具体如下: TP5 实现查询数据库返回json数据(返回json数据函数实例) 返回结果: 复制...

php的memcached客户端memcached

memcache的官方主页:http://pecl.php.net/package/memcachememcached的官方主页:http://pecl.php.net/package/...