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代码

之前碰到的这样一个需求,要将公司的服务在地图中显示出来,并将用户每天的访问坐标进行统计看有多少用户是在所能达到的服务范围半径内。 以下是PHP代码的实现 (仅验证坐标在某片坐标区域内)...

php恢复数组的key为数字序列的方法

本文实例讲述了php恢复数组的key为数字序列的方法。分享给大家供大家参考。具体分析如下: 这里实现php把数组的key值恢复成类似于0,1,2,3,4,5...这样的数字序列 fu...

两个php日期控制类实例

本文实例讲述了两个php日期控制类。分享给大家供大家参考。具体分析如下: 由于工作需要我找了二个时间日期控制,这个不用js只要php实现的,因为要带参考查询操作,感兴趣的朋友可以参考一下...

探讨如何在php168_cms中提取验证码

复制代码 代码如下:<?phpfunction yzImg($nmsg){ if (function_exists('imagecreatetruecolor')){&n...

PHP序列化操作方法分析

本文实例讲述了PHP序列化操作方法。分享给大家供大家参考,具体如下: 序列化就是将变量数据转换为字符串(跟类型转换机制不同),一般应用于存储数据(文件),然后在别的情形下恢复(反序列化)...