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 sprintf()函数让你的sql操作更安全

$bookSQL=sprintf("UPDATE book SET pass=%s WHERE id=%d",   ...

老生常谈PHP 文件写入和读取(必看篇)

老生常谈PHP 文件写入和读取(必看篇)

文章提纲: 一.实现文件读取和写入的基本思路 二.使用fopen方法打开文件 三.文件读取和文件写入操作 四.使用fclose方法关闭文件 五.文件指针的移动 六.Window...

PHP从零开始打造自己的MVC框架之类的自动加载实现方法详解

PHP从零开始打造自己的MVC框架之类的自动加载实现方法详解

本文实例讲述了PHP从零开始打造自己的MVC框架之类的自动加载实现方法。分享给大家供大家参考,具体如下: 前面介绍了MVC框架的入口文件,接下来我们希望完成一个“自动加载类”的功能,我们...

PHP实现的注册,登录及查询用户资料功能API接口示例

本文实例讲述了PHP实现的注册,登录及查询用户资料功能API接口。分享给大家供大家参考,具体如下: 服务端 <?php require 'conn.php'; head...

PHP中SERIALIZE和JSON的序列化与反序列化操作区别分析

本文实例讲述了PHP中SERIALIZE和JSON的序列化与反序列化操作区别。分享给大家供大家参考,具体如下: PHP中SERIALIZE和JSON序列化与反序列化区别是什么呢,对于这个...