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应用技巧

1、关于PHP重定向1、关于PHP重定向 方法一:header("Location: index.php"); 方法二:echo "<scrīpt>win...

PHP函数实现分页含文本分页和数字分页

PHP函数实现分页含文本分页和数字分页

最近,在项目中要用到分页。分页功能是经常使用的一个功能,所以,对其以函数形式进行了封装。 // 分页分装 /** * $pageType 分页类型 1是数字分页 2是文本分页 * 可...

PHP Cookie学习笔记

PHP Cookie学习笔记

什么是Cookie Cookie是一种在远程浏览器端存储数据并以此来跟踪和识别用户的机制。简单地说,Cookie是Web服务器暂时存储在用户硬盘上的一个文本文件,并随后被Web浏览器读取...

php开启openssl的方法

php开启openssl的方法,大多数情况下openssl是没有开启的,要想启用需要进行下简单的设置windows下开启方法: 1: 首先检查php.ini中;extension=php...

详解WordPress开发中wp_title()函数的用法

wp_title 函数在 WordPress 中是用来显示文章、页面、分类等等等等标题的一个函数,但在首页索引,该函数将不显示任何的东西。该函数在 WordPress 官方主题中一直被使...