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 /** 默认首页 **/ class DefaultController extends AppController { public functi...

PHP操作数组相关函数

ange($low, $high),range($low, $high, $step);//创建顺序值的数组如:range(1,4)为(1,2,3,4)又如range('a','z')...

PHP实现的常规正则验证helper公共类完整实例

本文实例讲述了PHP实现的常规正则验证helper公共类。分享给大家供大家参考,具体如下: 主要代码功能: 弥补平时项目对于验证功能这块的不严谨。具体细分的常规验证, 手机号/电话/小灵...

php cookie名使用点号(句号)会被转换

这个标题不是很严格,应该说可以使用点号的cookie名,但会被转换,你命名一个cookie: $_COOKIE[‘my.name'] = 1; 实际上你不能通过'my.name'在coo...

浅谈htmlentities 、htmlspecialchars、addslashes的使用方法

1、html_entity_decode():把html实体转换为字符。 Eg:$str = "just atest & 'learn to use '"...