php生成图片缩略图的方法

yipeiwu_com5年前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数据集构建JSON格式及新数组的方法

自己写了个PHP结果集转换成JSON格式的函数,可以直接调用:复制代码 代码如下:function RecordToJson($recordset) { $jstr='['; while...

php将文本文件转换csv输出的方法

本文实例讲述了php将文本文件转换csv输出的方法。分享给大家供大家参考。具体实现方法如下: 这个类提供了转换成固定宽度的CSV文件,快速,简便的方法,它可将SplFileObject用...

Laravel SQL语句记录方式(推荐)

Laravel SQL语句记录方式(推荐)

打印sql语句,直接在你执行SQL语句后输出 方法一:  $queries = DB::getQueryLog();  $a = end($queries); &n...

解决ajax+php中文乱码的方法详解

解决ajax+php中文乱码的方法详解

中文如果用表单提交的话,不会出现乱码,而用ajax提交就会出现乱码,这是什么原因呢?我的理解是,我在写源码的时候,一般用记事本写,保存的时候默认用ANSI编码,源码中也没有用“<m...

php数组分页实现方法

本文实例讲述了php数组分页实现方法。分享给大家供大家参考,具体如下: <?php $arr_click = array( array( 'clicks' =>...