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使用SOAP调用API操作示例

本文实例讲述了PHP使用SOAP调用API操作。分享给大家供大家参考,具体如下: /*图片转换为 base64格式编码*/ function base64EncodeImage($i...

基于递归实现的php树形菜单代码

本文实例讲述了基于递归实现的php树形菜单代码。分享给大家供大家参考。具体实现方法如下: 开发电子商务网站的时候,做了这个显示树形菜单的功能,用的递归实现的PHP树形菜单函数。具体代码如...

php使用cookie保存用户登录的用户名实例

本文实例讲述了php使用cookie保存用户登录的用户名的方法。分享给大家供大家参考。具体实现方法如下: 用户登录文件:login.php 复制代码 代码如下:<html>...

PHP实现根据图片色界在不同位置加水印的方法

本文实例讲述了PHP实现根据图片色界在不同位置加水印的方法。分享给大家供大家参考。具体如下: 在使用php编程的时候, 很多时候需要对上传的图片加水印,来确定图片版权和出处. 但是,一般...

PHP之变量、常量学习笔记

有关变量的传地址赋值 PHP 3 中,变量总是传值赋值。PHP 4 提供了另外一种方式给变量赋值:传地址赋值。使用传地址赋值,即简单地追加一个(&...