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函数算出两个文件的相对路径。例如$a="/a/b/c/d/e.php"; $b=...

PHP 数据结构 算法 三元组 Triplet

复制代码 代码如下: <?php /** * 三元组 Triplet * */ class Triplet { private $_data = null; // 初始化三元组 p...

PHP中的生成XML文件的4种方法分享

生成如下XML串 Xml代码复制代码 代码如下:<?xml version="1.0" encoding="utf-8"?><article> &nbs...

PHP5中新增stdClass 内部保留类

stdClass类是PHP的一个内部保留类,初始时没有成员变量也没成员方法,所有的魔术方法都被设置为NULL,可以使用其传递变量参数,但是没有可以调用的方法。stdClass类可以被继承...

PHP检查网站是否宕机的方法示例

本文实例讲述了PHP检查网站是否宕机的方法。分享给大家供大家参考,具体如下: <?php function Networkcheck($url){ $agent =...