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处理文件的小例子(解压缩,删除目录)

复制代码 代码如下:<?php  $dir =   './temp';$desc   =   'tar_tes...

PHP实现限制IP访问的方法

本文实例讲述了PHP实现限制IP访问的方法。分享给大家供大家参考,具体如下: //获取客户端ip if (getenv("HTTP_CLIENT_IP")) $ip = gete...

PHP应用跨时区功能的实现方法

PHP中要实现一个跨时区的应用,也就是不同时区登录的用户需要看到自己时区的时间,同时也要能够进行时区的切换。 这里的思路是,系统中所有存储的时间都是GMT(UTC)时间,用户登录时,根据...

php在项目中寻找代码的坏味道(综艺命名)

php在项目中寻找代码的坏味道(综艺命名)

漫画篇 查字典   这个是我比较习惯的方式,打开字典,把中文放进去,看它能给我什么好的名字。             &nb...

PHP基础陷阱题(变量赋值)

复制代码 代码如下: <?php $a=3; $b=6; if($a=5||$b=7){ $a++; $b++; } var_dump($a, $b); 陷阱一 把$a=5、$b...