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抽象类和接口相关知识点。分享给大家供大家参考,具体如下: 抽象类(一种抽象的类) 一、什么是抽象方法? 定义:一个方法如果没有方法体(一个方法,不使用{},直接使用分...

CodeIgniter 完美解决URL含有中文字符串

codeIgniter默认的配置下是不允许URL中包含非ASCII字符的,如果URL中含非ASCII字符,那么CI会毫不客气的抛出错误。本文章向码农介绍CodeIgniter 如何解决U...

Drupal 添加模块出现莫名其妙的错误的解决方法(往往出现在模块较多时)

状况如下: 1、点击保按钮后,不能正常转到页面,出现空白页面; 2、刷新页面,发出导航中许多项已经没有了,还存在的项点击也不能进入正常的页面。 测试了多次没有发现任何问题,多次重装、测试...

PHP的静态方法与普通方法用法实例分析

PHP的静态方法与普通方法用法实例分析

本文实例讲述了PHP的静态方法与普通方法用法。分享给大家供大家参考,具体如下: 代码 <?php class TestClass { public $attri...

PHP统计数值数组中出现频率最多的10个数字的方法

本文实例讲述了PHP统计数值数组中出现频率最多的10个数字的方法。分享给大家供大家参考。具体分析如下: 该问题属于TOPK范畴,统计单词出现频率,做报表,数据统计的时会常用! php代码...