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中使用glob函数实现一句话删除某个目录下的所有文件

收集自网上: 复制代码 代码如下: array_map('unlink',glob('*')); 抛砖引玉而已,有很多朋友可能还不知道有glob这个函数吧。更多的用法看手册吧。 PHP...

php 文件夹删除、php清除缓存程序

复制代码 代码如下: <?php header('content-type:text/html;charset=utf-8'); function delFile($fpath)...

一些 PHP 管理系统程序中的后门

我倒不怎么关心提示框,SABLOG怎么知道我的版本有漏洞呢,程序肯定有后门.每次登陆后台自动检测官方版本跟当前版本对比.嗯.后来找到了.在templates/admin/main.php...

用PHP代替JS玩转DOM的思路及示例代码

事情的起源比较简单,我需要把一个导航页的数据整理好写入数据库。一个比较直观的方法是对html文件进行分析,通用的方法是用php的正则表达式来匹配。但是这样做开发和维护都很困难,代码可读性...

php 遍历显示文件夹下所有目录、所有文件的函数,没有分页的代码

<pre> <?php /********************** 一个简单的目录递归函数 第一种实现办法:用dir返回对象 *******************...