php生成图片缩略图的方法

yipeiwu_com5年前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无限极分类原理

1.递归:程序调用自身的编程技巧称为递归 2.案例: /** * @param 递归 $[name] */ function deeploop(&$i=1){ echo...

php中DOMDocument简单用法示例代码(XML创建、添加、删除、修改)

共分四个文件,分别是创建、增加、删除、修改四个功能,变量都是写死的,改一改用$_POST方式接收就可以用了 //index.php 创建功能 复制代码 代码如下: <?php $x...

PHP中substr()与explode()函数用法分析

本文实例讲述了PHP中substr()与explode()函数用法。分享给大家供大家参考。具体方法如下: substr(string,start,length):本函数将字符串 stri...

php命名空间设计思想、用法与缺点分析

本文实例讲述了php命名空间设计思想、用法与缺点。分享给大家供大家参考,具体如下: 相比C#等语言,你可以在php函数里面随意定义变量并赋值,而不用担心覆盖了全局变量,或者类变量;你也可...

PHP Reflection API详解

PHP Reflection API是PHP5才有的新功能,它是用来导出或提取出关于类、方法、属性、参数等的详细信息,包括注释。 PHP Reflection API有: class...