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清空(删除)指定目录下的文件,不删除目录文件夹的实现代码

web 开发中我们可能会碰到需要将某个目录下的所有文件清空,但不删除这个目录下的子目录(当然也不会删除被删除的根目录)的情况。那么对于这种只删除文件而不删除目录的方法,你是如何处理的呢?...

PHP中的错误处理、异常处理机制分析

例: 复制代码 代码如下: <?php $a = fopen('test.txt','r'); //这里并没有对文件进行判断就打开了,如果文件不存在就会报错 ?> 那么正确...

浅析PHP中Session可能会引起并发问题

在进行Web应用程序开发的时候,人们经常会用Session存储数据。但可能有人不知道,在PHP中,Session使用不当可能会引起并发问题。印度医疗行业软件解决方案提供商Plus91 T...

PHP n个不重复的随机数生成代码

复制代码 代码如下:<?php //range 是将1到100 列成一个数组 $numbers = range (1,100); //shuffle 将数组顺序随即打乱 shuff...

PHP常用的小程序代码段

本文实例讲述了PHP常用的小程序代码段。分享给大家供大家参考,具体如下: 1.计算两个时间的相差几天 $startdate=strtotime("2009-12-09"); $end...