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

相关文章

phpstudy默认不支持64位php的解决方法

备忘一下: windows上用phpstudy比较简便,但是其默认的php所有版本都是32位的,有坑,比如int最大值。 所以从php官网 点击打开链接http://windows.ph...

PHP内存使用情况如何获取

PHP内置函数memory_get_usage()能返回当前分配给PHP脚本的内存量,单位是字节(byte)。在WEB实际开发中,这些函数非常有用,我们可以使用它来调试PHP代码性能。...

PHP nl2br函数 将换行字符转成 <br>

将换行字符转成 <br> 。 语法 : string nl2br(string string); 返回值 : 字符串 函数种类 : 资料处理 内容说明 本函数将换行字符转换成...

php使用curl简单抓取远程url的方法

本文实例讲述了php使用curl抓取远程url的方法。分享给大家供大家参考。具体如下: cURL是一个非常有用的php库,可以用来连接不通类型的服务器和协议,下面是一个最基本的范例用来抓...

PHP使用SOAP调用API操作示例

本文实例讲述了PHP使用SOAP调用API操作。分享给大家供大家参考,具体如下: /*图片转换为 base64格式编码*/ function base64EncodeImage($i...