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将两个关联数组合并函数提高函数效率

在foreach中循环查询数据代码量比较少,但是性能比较低,好点的解决办法是将id收集起来,用in一次性查询,但是这引发了数据结构不是我们用PHP自带的函数可以合并的,今天测试了一下:...

使用php检测用户当前使用的浏览器是否为IE浏览器

复制代码 代码如下: /** * 检测用户当前浏览器 * @return boolean 是否ie浏览器 */ function chk_ie_browser() { $userbrow...

php删除页面记录 同时刷新页面 删除条件用GET方式获得

功能: 1、在某个页面上显示查询数据,并在每条数据后增加删除功能,点击“删除”,删除掉数据,同时刷新页面 2、用GET方式获得删除条件 数据库连接变量connectvars.php 复制...

php 短链接算法收集与分析

短链接就不说了,大家已经都清楚了,如下所示就是短链接: 新浪微博 http://t.cn/SVpONM 腾讯微博 http://url.cn/302yor Yun.io http://d...

PHPExcel实现表格导出功能示例【带有多个工作sheet】

本文实例讲述了PHPExcel实现表格导出功能。分享给大家供大家参考,具体如下: 首先得去下载phpexcel文档,解压下来 <?php /** * 简单实用Exec...