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随机生成数字字母组合的方法。分享给大家供大家参考。具体如下: 直接上代码: 复制代码 代码如下:function getRandomString($len, $cha...

PHP中4种常用的抓取网络数据方法

本小节的名称为 fsockopen,curl与file_get_contents,具体是探讨这三种方式进行网络数据输入输出的一些汇总。关于 fsockopen 前面已经谈了不少,下面开始...

php取得字符串首字母的方法

本文实例讲述了php取得字符串首字母的方法。分享给大家供大家参考。具体实现方法如下: <?php $limit = array( //gb2312 拼音排序 arr...

浅谈php的优缺点

一、优点 1. 跨平台,性能优越,跟Linux/Unix结合别跟Windows结合性能强45%,并且和很多免费的平台结合非常省钱,比如LAMP(Linux /Apache/Mysql/P...

浅谈本地WAMP环境的搭建

在php本地搭建过程中,php环境配置是至关重要的一部分,本文就php在本地的环境配置中作简要说明。以供大家学习! 配置Windows+Apache+Mysql+PHP开发运行环境 安装...