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在不同页面间传递Json数据示例代码

gettest.php文件: 复制代码 代码如下: <?php $value["name"]= urlencode("我的姓名"); $value["pass"]= urlenco...

php $_ENV为空的原因分析

但有些朋友的$_ENV是空的,可能是原因是: 你的php.ini的variables_order值为"GPCS",也就是说系统在定义PHP预定义变量时的顺序是GET,POST,COOKI...

PHP面向对象程序设计组合模式与装饰模式详解

本文实例讲述了PHP面向对象程序设计组合模式与装饰模式。分享给大家供大家参考,具体如下: 组合模式 定义:组合模式定义了一个单根继承体系,使具有截然不同职责的集合可以并肩工作。 一个军队...

php获取后台Job管理的实现代码

复制代码 代码如下: <?php defined('SYSPATH') OR die('No direct access allowed.'); class Controller_...

浅析PHP中Session可能会引起并发问题

在进行Web应用程序开发的时候,人们经常会用Session存储数据。但可能有人不知道,在PHP中,Session使用不当可能会引起并发问题。印度医疗行业软件解决方案提供商Plus91 T...