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实现推荐功能的简单实例

利用similar_text将这些文章标题同原文章标题做对比,按标题的相似程度重新排列标题,就得到了与原文章相似的文章列表。 <?php $demo_title= "...

PHP中遇到BOM、&lt;feff&gt;编码导致json_decode函数无法解析问题

昨天同事遇到一个奇怪的问题,就是以下代码,无法通过JSON校验,也无法通过PHP的json_decode函数解析。 复制代码 代码如下: [     { &...

提高define性能的php扩展hidef的安装和使用

提高define性能的php扩展hidef的安装和使用

官网:http://pecl.php.net/package/hidef简介:  Allow definition of user defined constants in simple...

phpMyAdmin出现无法载入 mcrypt 扩展,请检查PHP配置的解决方法

1、没有正确安装Mysql数据库,在系统服务中Mysql相关的服务没有启动 (请查看正确安装Mysql的方法) 2、在系统的 system32(C:\windows\system32)...

php绝对路径与相对路径之间关系的的分析

php绝对路径与相对路径之间关系的的分析

php中好像不能像asp那样用“/”表示根目录,代之以$_SERVER['DOCUMENT_ROOT'],其它则相同:../表示向上一层。./表示当前层。假如现在a/b/c/s.php要...