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

相关文章

The specified CGI application misbehaved by not returning a complete set of HTTP headers

是错误报告: The specified CGI application misbehaved by not returning a complete set of HTTP heade...

php判断字符以及字符串的包含方法属性

下面介绍使用方法: 1. strstr: 返回一个从被判断字符开始到结束的字符串,如果没有返回值,则不包含 复制代码 代码如下:<?php /*如手册上的举例*/ $email =...

PHP使用pdo实现事务处理操作示例

本文实例讲述了PHP使用pdo实现事务处理操作。分享给大家供大家参考,具体如下: 使用事务的好处: 举个例子:银行用户A向用户B转账100元,这个操作被分为两个步骤: (1)A的账户余额...

php实现的生成迷宫与迷宫寻址算法完整实例

php实现的生成迷宫与迷宫寻址算法完整实例

本文实例讲述了php实现的生成迷宫与迷宫寻址算法。分享给大家供大家参考,具体如下: 较之前的终于有所改善。生成迷宫的算法和寻址算法其实是一样。只是一个用了遍历一个用了递归。参考了网上的M...

php 判断字符串中是否包含html标签

function judgeHtml($str){ if($str != strip_tags($str)){  echo '有'; }else{...