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实现有趣的人品测试程序。分享给大家供大家参考。具体实现方法如下: <html> <head> <meta http-equiv="C...

PHP下一个非常全面获取图象信息的函数

复制代码 代码如下:<?php function getimageinfo(img) { //img为图象文件绝对路径 img_info = getimagesize(img);...

PHP实现数组的笛卡尔积运算示例

本文实例讲述了PHP实现数组的笛卡尔积运算。分享给大家供大家参考,具体如下: 数组的笛卡尔积在实际中还是挺有用处的,比如计算商品的规格时就经常用到,下面写一种实现方式,如下代码 $a...

php进行md5加密简单实例方法

直接可以使用md5()函数,对内容进行加密,如:md5($admin_pw) 把这段密文分割成若干段,对每段都进行一次MD5运算,然后把这堆密文连成一个超长的字符串,最后再进行一次MD5...

PHP array_shift()用法实例分析

本文实例讲述了PHP array_shift()用法。分享给大家供大家参考,具体如下: array_shift()将数组开头的单元移出数组,并作为结果返回,将数组长度减一并将所有其它单元...