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程序设计有所帮助。

相关文章

echo, print, printf 和 sprintf 区别

- echo  是命令,不能返回值。echo后面可以跟很多个参数,之间用分号隔开,如:  echo $myvar1;  echo&nbs...

PHP中英混合字符串截取函数代码

复制代码 代码如下: function get_word($string, $length, $dot = '..',$charset='gbk') { if(strlen($strin...

PHP实现cookie跨域session共享的方法分析

PHP实现cookie跨域session共享的方法分析

本文实例讲述了PHP实现cookie跨域session共享的方法。分享给大家供大家参考,具体如下: 做过web开发的小伙伴们都了解cookie和session,cookie是存储在客户端...

php 实现svg转化png格式的方法分析

php 实现svg转化png格式的方法分析

本文实例讲述了php 实现svg转化png格式的方法。分享给大家供大家参考,具体如下: svg转png实现 1.php imagick扩展插件 a.研究imagick插件方法 $im...

jQuery获取json后使用zy_tmpl生成下拉菜单

第一次写关于AppCan开发的文章,有人写了关于jQuery或者原生Ajax与json的交互,那我就稍微写写我开发过程中使用jQuery获取json后使用zy_tmpl生成下拉菜单的实例...