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下汉字转化为拼音的代码第1/2页

复制代码 代码如下: <?php $d = array( array("a",-20319), array("ai",-20317), array("an",-20304), ar...

php foreach 参数强制类型转换的问题

所以,为了防止这样的信息出现,我使用foreach的时候,都会把参数进行强制类型转换,形势如下: foreach((array)$arr as $key => $value); 这...

PHP获取数组长度或某个值出现次数的方法

本文实例讲述了PHP获取数组长度或某个值出现次数的方法。分享给大家供大家参考。具体分析如下: count():对数组中的元素个数进行统计; 例如: $arr = Array('0',...

PHP实现读取一个1G的文件大小

需求如下: 现有一个1G左右的日志文件,大约有500多万行, 用php返回最后几行的内容。 1. 直接采用file函数来操作 or file_get_content() 肯定报内存溢出注...

PHP基于关联数组20行代码搞定约瑟夫问题示例

PHP基于关联数组20行代码搞定约瑟夫问题示例

本文实例讲述了PHP基于关联数组20行代码搞定约瑟夫问题。分享给大家供大家参考,具体如下: 记得前段时间一写做java开发的兄弟对我说他java60行做了个约瑟夫问题,挺不错的。调侃ph...