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集成开发环境详解

HP开发使用的集成环境,可用PHPStorm, 或者用免费版的 IDEA 加 PHP 插件,两者功能基本相同,只是后者安装起来略折腾。 PHPStorm的特点:跨平台,我在 Window...

PHP面向对象程序设计之构造方法和析构方法详解

PHP面向对象程序设计之构造方法和析构方法详解

本文实例讲述了PHP面向对象程序设计之构造方法和析构方法。分享给大家供大家参考,具体如下: 构造方法和析构方法是对象中的两个特殊方法,它们都与对象的生命周期有关。构造方法是对象创建完成后...

解析CI的AJAX分页 另类实现方法

看了一下CI的分页类没有写到关于AJAX的内容,也在论坛上看到其他几位大神写的分页类扩展,感觉其实是没有必要。在现有的基础上做了一下小小的改动还是能实现的。下面进入正题:CI的原生分页类...

PHP使用PDO访问oracle数据库的步骤详解

前言 PDO 从一开始就吸取了现有数据库扩展成功和失败的经验教训。因为 PDO 的代码是全新的,所以我们有机会重新开始设计性能,以利用 PHP 5 的最新特性。 PDO 旨在将常见的数...

PHP函数shuffle()取数组若干个随机元素的方法分析

本文实例讲述了PHP函数shuffle()取数组若干个随机元素的方法。分享给大家供大家参考,具体如下: 有时候我们需要取数组中若干个随机元素(比如做随机推荐功能),那么PHP要如何实现呢...