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中phar包的使用教程

前言 PHP5.3之后支持了类似Java的jar包,名为phar。用来将多个PHP文件打包为一个文件。 首先需要修改php.ini配置将phar的readonly关闭,默认是不能写pha...

php XMLWriter类的简单示例代码(RSS输出)

复制代码 代码如下: include 'mysql.php'; $mysql= mysql::getObject(); $mysql->query("SELECT * FROM p...

THINKPHP内容分页代码分享

在使用Thinkphp开发的内容管理系统里面,很多东西都要自己开发,内容分页当然也是要自己开发的,下面是我根据查资料自己整理的方法: 1、首先是在后台编辑内容的时候需要插入分页符,不同的...

PHP运行时强制显示出错信息的代码

复制代码 代码如下: error_reporting(E_ALL); ini_set('display_errors', '1'); ini_set('error_log', dirna...

PHP连接MSSQL2008/2005数据库(SQLSRV)配置实例

本文实例讲述了PHP连接MSSQL2008/2005数据库(SQLSRV)配置方法,分享给大家供大家参考。具体方法如下: PHP连接MSSQL2008/2005数据库与以往的连接mssq...