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程序设计有所帮助。

相关文章

apache和PHP如何整合在一起

apache和PHP如何整合在一起

一般安装好PHP之后,apache并不能处理php文件,要想使得php与apache服务器整合在一起,必须修改配置文件,这里我教大家如何配置php安装文件。 方法/步骤 首先在apach...

php如何比较两个浮点数是否相等详解

前言 本文主要给大家介绍了关于利用php如何比较浮点数是否相等的相关内容,下面话不多说了,来一起看看详细的介绍吧 看下面这段代码, 0.9+0.1 的相加结果与 1 进行比较 &...

PHP 可阅读随机字符串代码

复制代码 代码如下: /************** *@length - length of random string (must be a multiple of 2) *****...

PHP+redis实现微博的拉模型案例详解

本文实例讲述了PHP+redis实现微博的拉模型。分享给大家供大家参考,具体如下: 上回写了一篇推模型的内容,这回分享一篇拉模型的内容。 拉模型 拉模型就是展示微博的时候,获取自己的所有...

PHP实现的简单路由和类自动加载功能

本文实例讲述了PHP实现的简单路由和类自动加载功能。分享给大家供大家参考,具体如下: 项目目录如下 入口文件index.php <?php define('WEBROO...