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用GD库生成高质量的缩略图片

以下是PHP源代码(ResizeImage.php)。 复制代码 代码如下: <?php $FILENAME="image.thumb"; // 生成图片的宽度 $RESIZEWI...

php输出xml格式字符串(用的这个)

复制代码 代码如下: <?php header("Content-type:text/xml;charset=utf-8"); $aaa =<<<html <...

php识别翻转iphone拍摄的颠倒图片

用iphone横向拍摄并上传的图片往往是向左或向右90度侧向显示的,本文介绍如何用php识别并且翻转图片到正确位置。 ps : 此方法只能判断一些手机相机拍摄的图片位置颠倒 ...

PHP实现UTF8二进制及明文字符串的转化功能示例

本文实例讲述了PHP实现UTF8二进制及明文字符串的转化功能。分享给大家供大家参考,具体如下: <?php /***********本程序由云客编写。有空的时候承接ph...

is_uploaded_file函数引发的不能上传文件问题

起因: 在一个项目中,接到用户反馈说其所有客户不能上传文件,都返回失败。经过排查发现是PHP中的is_uploaded_file函数在捣鬼。 细节分析: 在正常情况下,通过PHP 上传文...