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注入方法集锦第1/2页

'%23  ' and passWord='mypass  id=-1 union select 1,1,1&nbs...

php使用exec shell命令注入的方法讲解

使用系统命令是一项危险的操作,尤其在你试图使用远程数据来构造要执行的命令时更是如此。如果使用了被污染数据,命令注入漏洞就产生了。exec()是用于执行shell命令的函数。它返回执行并返...

php输出xml必须header的解决方法

本文实例讲述了php输出xml必须header的解决方法。分享给大家供大家参考。具体方法如下: 问题描述: 最近在做一个xml输出时发现我们直接使用echo输入的xml文档会提示Erro...

PHP has encountered an Access Violation at 7C94BD02解决方法

解决方法如下: php for windows的bug 参考: 第一种可能: 去掉 php中 eaccelerator 的扩展 这样做能够解决您的问题,不过可能会加重系统负担 因为eac...

mod_php、FastCGI、PHP-FPM等PHP运行方式对比

概述 写这篇文章的是因为今天要Ubuntu下搭建LNMP环境,Nginx使用的是PHP-FPM,所以对Web服务器与PHP解释器的交互方式做了个整理。 众所周知,PHP是跨平台、跨服务器...