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 json_decode可能遇到的坑与解决方法

前言 最近在做网站 的时候用到了json_decode函数,发现了一个问题,现在总结分享出来供大家参考学习,话不多说了,来一起看看详细的介绍吧。 场景: 某项目客户反馈,输出的结果 JS...

php强制更新图片缓存的方法

本文实例讲述了php强制更新图片缓存的方法。分享给大家供大家参考。具体实现方法如下: 复制代码 代码如下:/** 強制更新圖片緩存 *   @param Array...

php分页函数完整实例代码

本文分享一例php分页函数完整实例代码,使用此函数实现分页效果很不错。分享给大家供大家参考。 具体功能代码如下: <?php /* * Created on 2011-...

PHP有序表查找之二分查找(折半查找)算法示例

本文实例讲述了PHP有序表查找之二分查找(折半查找)算法。分享给大家供大家参考,具体如下: 简介: 二分查找技术,又称为折半查找。它的前提是线性表中的记录必须是关键码有序(通常从小到达有...

利用php绘制饼状图的实现代码

drawPieImg()函数包含8个参数,$title为饼状图的标题;$dataArr为需要显示的数据数组;$labelArr为对应数据的标签分类数组;$colorArr为对应数据的绘图...