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保存Base64图片base64_decode的问题整理

PHP对Base64的支持非常好,有内置的base64_encode与base64_decode负责图片的Base64编码与解码。 编码上,只要将图片流读取到,而后使用base64_en...

PHP实现数组根据某个单元字段排序操作示例

本文实例讲述了PHP实现数组根据某个单元字段排序操作。分享给大家供大家参考,具体如下: 如题,给出一个PHP数组,数组结构如下: $arr = array( array(...

php中计算时间差的几种方法

一个简单的例子就是计算借书的天数,这需要php根据每天的日期进行计算,下面就来谈谈实现这种日期计算的几种方法: (1) 如果有数据库就很容易了!若是MSSQL可以使用触发器!用专门计算日...

PHP通过正则表达式下载图片到本地的实现代码

复制代码 代码如下:<?php /* author: ssh_kobe date: 20110602 shortage: 如果网页中的图片路径不是绝对路径,就无法抓取 */ set...

PHP 长文章分页函数 带使用方法,不会分割段落,翻页在底部

复制代码 代码如下: <?php function ff_page($content,$page) { global $expert_id; $PageLength = 2000;...