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程序设计有所帮助。

相关文章

利用PHPExcel读取Excel的数据和导出数据到Excel

利用PHPExcel读取Excel的数据和导出数据到Excel

PHPExcel是一个PHP类库,用来帮助我们简单、高效实现从Excel读取Excel的数据和导出数据到Excel。也是我们日常开发中,经常会遇到的使用场景。比如有个客户信息表,要批量导...

asp.net Repeater控件的说明及详细介绍及使用方法

Repeater 控件不具备内置的呈现功能,这表示用户必须通过创建模板为 Repeater 控件提供布局。当该页运行时,Repeater 控件依次通过数据源中的记录为每个记录呈现一个项。...

PHP入门教程之字符串处理技巧总结(转换,过滤,解析,查找,截取,替换等)

本文实例总结了PHP字符串处理技巧。分享给大家供大家参考,具体如下: Demo1.php <?php //源代码是文本形式,页面显示是 web 形式 $str...

PHP面向对象程序设计内置标准类,普通数据类型转为对象类型示例

本文实例讲述了PHP面向对象程序设计内置标准类,普通数据类型转为对象类型。分享给大家供大家参考,具体如下: 内置标准类 PHP中,有很多“现成的类”,其中有一个被称为“内置标准类”。这个...

PHP 防注入函数(格式化数据)

复制代码 代码如下: <? //格式化数据(防止注入) function site_addslashes($string, $force = 0) { !defined('MAGI...