php生成图片缩略图的方法

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

相关文章

CodeIgniter与PHP5.6的兼容问题

错误提示: A PHP Error was encountered Severity: Notice Message: Only variable references shou...

PHP文件上传原理简单分析

//表单上传只能使用multipart/form-data编码格式 $_FILES系统函数; $_FILES['myFile']['name']文件名称 $_FILES['myFile'...

用 PHP5 轻松解析 XML

用 sax 方式的时候,要自己构建3个函数,而且要直接用这三的函数来返回数据,要求较强的逻辑。在处理不同结构的 xml 的时候,还要重新进行构造这三个函数,麻烦! 用 dom 方式,倒是...

PHP中cookie知识点学习

什么是cookie cookie,即小饼干,是保存在用户代理端(浏览器是最常见的用户代理)的一些数据片段。浏览网页时,浏览器会将 当前页面有效的 cookie放在请求的头部发送到服务端。...

php + nginx项目中的权限详解

本文给大家介绍的关于php + nginx项目权限的相关内容,分享出来供大家参考学习,下面来看看详细的介绍: nginx/php-fpm 进程权限 主进程用户为启动的用户...