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上传图片类(随机名,缩略图,加水印)

Upimages.class.php php上传类复制代码 代码如下:<?php class UpImages { var $annexFolder = "upload";//附件...

Linux系统下php获得系统分区信息的方法

本文实例讲述了Linux系统下php获得系统分区信息的方法。分享给大家供大家参考。具体实现方法如下: $pars = array_filter(explode("\n",`df -h...

解析php取整的几种方式

floor 舍去法取整 语法格式:float floor ( float value )返回不大于value 的下一个整数,将value 的小数部分舍去取整。floor() 返回的类型仍...

php不写闭合标签的好处

最早这个概念是从Drupal中接触到的,一开始有点不习惯——为什么不写闭合标签呢?这感觉很不完美啊,对于有强迫症的人来说很不适应嘛!后来,在工作中碰到了因为标签闭合而引起的问题,才开始不...

php magic_quotes_gpc的一点认识与分析

blankyao 说“学习的过程就是不断的发现错误,不断的改正错误”; 先看下手册上怎么说的吧! 对一般人来说看下前两段就可以了 Magic Quotes 代码: Magic Quote...