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做推送服务端实现ios消息推送

准备工作1.获取手机注册应用的deviceToken(iphone手机注册应用时返回唯一值deviceToken)2.获取ck.pem文件(做手机端的给)3.获取pass phrase(...

解决file_get_contents无法请求https连接的方法

错误: Warning: fopen() [function.fopen]: Unable to find the wrapper "https" - did you forget to...

PHP基于非递归算法实现先序、中序及后序遍历二叉树操作示例

PHP基于非递归算法实现先序、中序及后序遍历二叉树操作示例

本文实例讲述了PHP基于非递归算法实现先序、中序及后序遍历二叉树操作。分享给大家供大家参考,具体如下: 概述: 二叉树遍历原理如下: 针对上图所示二叉树遍历: 1. 前序遍历:先遍历根...

php代码架构的八点注意事项

本文总结讲述了php代码架构的八点注意事项。分享给大家供大家参考,具体如下: 写代码写了6年多了,看看以前的架构,看看现在的架构。都有一些不足的地方。不管怎么样,都一直在改进。说实话不太...

关于PHP语言构造器介绍

PHP里有echo、print、die、require等几个特殊的关键字,虽然它们用起来像是函数,但实际上更类似于if、while这样控制语句,而不是一个函数。也就是说,当解释器遇到:...