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封装的图片(缩略图)处理类完整实例

本文实例讲述了php封装的图片(缩略图)处理类。分享给大家供大家参考,具体如下: <?php //图片处理工具类 class Image{ //属性 p...

用php过滤危险html代码的函数

#用户发布的html,过滤危险代码  function uh($str)  {  $farr = array(  "...

PHP聊天室简单实现方法详解

PHP聊天室简单实现方法详解

本文实例讲述了PHP聊天室简单实现方法。分享给大家供大家参考,具体如下: 用户 => 客服 (先把信息入库,然后通过ob+长连接不断从数据库查询数据发送给客服) 客服 =>...

php制作中间带自己定义图片二维码的方法

1,首先你必须生成二维码具体代码如下: 复制代码 代码如下: class QRCode{ public $w; public $h; public $s; function __cons...

PHP获取ttf格式文件字体名的方法示例

本文实例讲述了PHP获取ttf格式文件字体名的方法。分享给大家供大家参考,具体如下: <?php $names = GetFontName('c:/windows/fo...