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 eval函数使用介绍

代码: eval("echo'hello world';"); 上边代码等同于下边的代码: echo"hello world"; 在浏览器中都输出:hello world 运用ev...

PHP函数按引用传递参数及函数可选参数用法示例

本文实例讲述了PHP函数按引用传递参数及函数可选参数用法。分享给大家供大家参考,具体如下: 一、函数按引用传递参数 1. 代码 <!DOCTYPE html PUBLIC "-...

PHP、Nginx、Apache中禁止网页被iframe引用的方法

可以使用php或nginx等添加X-Frame-Options header来控制frame权限X-Frame-Options有三个可选的值: DENY:浏览器拒绝当前页面加载任何Fra...

php优化及高效提速问题的实现方法第1/2页

一、 在函数中,传递数组时使用 return 比使用 global 要高效,比如: function userloginfo($usertemp){ $detail=explode("|...

PHP简单实现二维数组赋值与遍历功能示例

本文实例讲述了PHP简单实现二维数组赋值与遍历功能。分享给大家供大家参考,具体如下: 示例1: <?php $loptop1['lid'] = 1000; $l...