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绘制在图片上的正余弦曲线

以前用actionscript写动态绘制三角函数曲线,其实php输出三角函数曲线也很简单。复制代码 代码如下:<?php define("MAX_WIDTH_PIXEL"...

PHP定时更新程序设计思路分享

现在回想起来,我以前的想法是错误的,网页的执行流程  打开WEB页面 —- 加载HTML代码 (包括CSS,javascript)— 执行PHP代码 — 完成 粗约的就先理解...

php获得url参数中具有&的值的方法

实际在项目过程中,我们经常会遇到要获取上一页地址的路径。你可以返回上一页使用 复制代码 代码如下: <script>window.history.go(-1);</sc...

PHP CURL使用详解

PHP CURL是一个非常强大的开源库,支持很多协议,包括HTTP、FTP、TELNET等,我们使用它来发送HTTP请求。它给我们带来的好处是可以通过灵活的选项设置不同的HTTP协议参数...

javascript some()函数用法详解

参数说明 callback: 要对每个数组元素执行的回调函数。 thisObject : 在执行回调函数时定义的this对象。 功能说明 对数组中的每个元素都执行一次指定的函数(call...