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 //循环遍历目录中所有的文件,并统计目录和文件的大小 $d...

PHP setcookie设置Cookie用法(及设置无效的问题)

结果碰到一个问题,setcookie设置了Cookie并没有生效,在浏览器端也没有看到。查了一下,原来是setcookie是通过HTTP请求响应的Header来完成的,需要在请求响应内容...

PHP判断远程图片或文件是否存在的实现代码

最简单的方法就是用fopen(),看看文件能否打开,能打就文件当然就存在复制代码 代码如下:<?php$url = '//www.jb51.net/images/test.jpg'...

php自动加载方式集合

php加载文件方式: 1、include,include_once,requice,requice_one常规加载 2、__autoload() 3、spl_autoload_regis...

PHP单文件上传原理及上传函数的封装操作示例

本文实例讲述了PHP单文件上传原理及上传函数的封装操作。分享给大家供大家参考,具体如下: 表单: 0.php: <!doctype html> <html>...