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中怎样保持SESSION不过期 原理及方案介绍

PHP中如何保持SESSION以及由此引发的一些思考  最近的一个项目,里面有一个比较大的表单,用户完成它需要很多时间,很多用户花了千辛万苦完成之后,一提交发现SESSION过...

PHP获取http请求的头信息实现步骤

PHP手册提供了现成的函数: getallheaders (PHP 4, PHP 5) getallheaders — Fetch all HTTP request headers 说明...

PHP fclose函数用法总结

php fclose()函数 语法 作用:关闭一个打开文件 语法: fclose(file) 参数: file 必需。规定要关闭的文件。 说明:如果成功则返回 true,否则返回...

汇总PHPmailer群发Gmail的常见问题

大家在PHPmailer群发Gmail时会遇到许多常见问题,下面为大家总结了一些常见问题,希望对大家的学习有所帮助。 1.Could not authenticate 首先,如果你没有使...

PHP面向接口编程 耦合设计模式 简单范例

复制代码 代码如下: <?php interface js{ function ys($a,$b); } class Af implements js{ function ys($...