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程序设计有所帮助。

相关文章

手把手教你使用DedeCms V3的在线采集图文教程

手把手教你使用DedeCms V3的在线采集图文教程

这是我们要采集的目标网址-------------------------------------------------------------screen.width*0.7) {t...

PHP数组的交集array_intersect(),array_intersect_assoc(),array_inter_key()函数的小问题

返回一个交集共有元素的数组(只是数组值得比较)、array_intersect_assoc()函数是将键值和值绑定,一起比较交集部分、array_intersect_key()函数是将两...

php 数组的创建、调用和更新实现代码

复制代码 代码如下:<?php $array = array("key1" => "Simon", 2 => "Elaine"); //数组的创建 echo $arra...

php无限分类且支持输出树状图的详细介绍

php无限分类且支持输出树状图的详细介绍

复制代码 代码如下:<?php/*** 通用的树型类,可以生成任何树型结构*/class tree{    /**   ...

php中的常用魔术方法汇总

这篇文章详细的对php中的常用魔术方法进行了整理归纳,分享给大家供大家参考,具体内容如下 1、PHP把所有”__”开头的方法当做魔术方法,所以任何自定义的方法都不能是”__”开头 php...