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接口多继承及tarits实现多继承效果的方法

本文实例讲述了PHP接口多继承及tarits实现多继承效果的方法。分享给大家供大家参考,具体如下: 接口多继承 在PHP的面向对象中,接口可以继承接口。PHP类只能继承一个父类(单继承)...

PHP音乐采集(部分代码)

<?PHP set_time_limit(0); mysql_connect("localhost","root",""); mysql_select_Db("music_36g"...

php类自动加载器实现方法

本文实例讲述了php类自动加载器实现方法。分享给大家供大家参考。具体如下: 这里autoload 可兼容以下格式: Cache_File_Json class_xxx.php xxx...

PHP获取网站域名和地址的代码

复制代码 代码如下:<? function PMA_getenv($var_name) { if (isset($_SERVER[$var_name])) { return $_S...

讲解WordPress中用于获取评论模板和搜索表单的PHP函数

comments_template()(获取评论模板) comments_template() 函数用来获取评论模板,一般只能用在文章或者页面上,如果不是文章或者页面将无法显示。 用法...