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代码

复制代码 代码如下: define(CHARSET, 'UTF-8'); // 系统默认编码 /** * 根据中文裁减字符串 * @param $string - 字符串 * @para...

php 远程关机操作的代码

<?php /** * 远程启动计算机 * 注意:iis/apache需要有windows/system/cmd.exe执行权限 * name:薛如飞 * qq:6706250 *...

本地计算机无法启动Apache故障处理

最近因工作需要,要学习PHP的基础编程,于是学习架设PHP工作环境。 但按照教材上介绍的那样,安装了WMAP后,一直无法运行成功。后发现Apache一直都不在运行状态。到WMAP中的Ap...

PHP设计模式之装饰器模式实例详解

PHP设计模式之装饰器模式实例详解

本文实例讲述了PHP设计模式之装饰器模式。分享给大家供大家参考,具体如下: 装饰器模式又叫装饰者模式。装饰模式是在不必改变原类文件和使用继承的情况下,动态地扩展一个对象的功能。它是通过创...

php开启安全模式后禁用的函数集合

复制代码 代码如下: <?php ini_set("safe_mode",true); ?> 表 42-2. 安全模式限制函数 函数名 限制 dbmopen...