最新消息:

PHP类第8款:SimpleImage.class.php生成缩略图类

PHP类 杨红伟 5510浏览 0评论

一:类介绍

本来是查一款PHP的生成缩略图的函数,无意中看到了它。觉得它还是特别的好用,于是想总结并分享一下,相比较个人之前使用的一些生成缩略图的方法,这算是一款比较好用的方法了。

它是于 Simon Jarvis 于 2006年8月11日写的,距离至今2015年1月已经有9个年头了。在8年多的时间了,PHP发生了很多变化,版本也进行了很多更新,但作者在使用时也没有发生错误,于是查看了一下源代码,基本就是一些对图片处理的基本函数,使用起来还是非常方便快捷的!

二:类下载与作者

类的名称: SimpleImage.class.php 原名为  SimpleImage.php ,为了方便使用,中间加了一个class

类的官方下载地址:目前找不到官方下载地址

类的本站下载地址: http://www.ijquery.cn/phpclass/SimpleImage/SimpleImage.zip

类的作者:Simon Jarvis

类的版本:08/11/06

三:类的特性

load //加载图片地址
save //保存图片
output //输出图片
getWidth  //获取图片的宽度
getHeight  //获取图片的高度
resizeToHeight  //重置高度-等比缩放
resizeToWidth  //重置图片的宽度-等比缩放
scale  //按百分比重置图片
resize  //重新写图片的宽和高
resize2  //重新写图片的宽和高2

四:类的使用

1、设定宽度,等比例缩放

演示地址: http://www.ijquery.cn/phpclass/SimpleImage/demo1.php

<?php
header("Content-Type: text/html; charset=utf-8");
//设定宽度,等比例缩放
include ('class/SimpleImage.class.php');
$image = new SimpleImage();
$image -> load('flower.jpg');
$image -> resizeToWidth(250);
$image -> save('flower250.jpg');

2、设定高度,等比例缩放

演示地址: http://www.ijquery.cn/phpclass/SimpleImage/demo2.php

<?php
header("Content-Type: text/html; charset=utf-8");
//设定高度,等比例缩放
include ('class/SimpleImage.class.php');
$image = new SimpleImage();
$image -> load('flower.jpg');
$image -> resizeToHeight(500);
$image -> save('flower500.jpg');

3、按比例,缩放至50%

演示地址: http://www.ijquery.cn/phpclass/SimpleImage/demo3.php

<?php
header("Content-Type: text/html; charset=utf-8");
//按比例,缩放至50%
include ('class/SimpleImage.class.php');
$image = new SimpleImage();
$image -> load('flower.jpg');
$image -> scale(50);
$image -> save('flower50.jpg');

4、缩放后直接输出到屏幕

演示地址: http://www.ijquery.cn/phpclass/SimpleImage/demo4.php

<?php
header("Content-Type: text/html; charset=utf-8");
//缩放后直接输出到屏幕
header('Content-Type: image/jpeg');
include ('class/SimpleImage.class.php');
$image = new SimpleImage();
$image -> load('flower.jpg');
$image -> resizeToWidth(150);
$image -> output();


Warning: Use of undefined constant PRC - assumed 'PRC' (this will throw an Error in a future version of PHP) in /www/wwwroot/www.ijquery.cn/wp-content/themes/d8-3.0/comments.php on line 17
发表我的评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址