| 包 | helper | 
|---|---|
| 类层次 | class Helper_Image | 
| 版本 | $Id: image.php 1937 2009-01-05 19:09:40Z dualface $ | 
Helper_Image 类封装了针对图像的操作
开发者不能直接构造该类的实例,而是应该用 Helper_Image::createFromFile() 静态方法创建一个 Image 类的实例。
操作大图片时,请确保 php 能够分配足够的内存。
| 方法 | 描述 | 定义于 | 
|---|---|---|
| createFromFile() | 从指定文件创建 Helper_ImageGD 对象 | Helper_Image | 
| hex2rgb() | 将 16 进制颜色值转换为 rgb 值 | Helper_Image | 
public static Helper_ImageGD createFromFile($filename, $fileext)
| $filename | string | 图像文件的完整路径 | 
| $fileext | string | 指定扩展名 | 
| {return} | Helper_ImageGD | 从文件创建的 Helper_ImageGD 对象 | 
从指定文件创建 Helper_ImageGD 对象
用法:
$image = Helper_Image::createFromFile('1.jpg'); $image->resize($width, $height); $image->saveAsJpeg('2.jpg');
对于上传的文件,由于其临时文件名中并没有包含扩展名。 因此需要采用下面的方法创建 Image 对象:
$ext = pathinfo($_FILES['postfile']['name'], PATHINFO_EXTENSION); $image = Image::createFromFile($_FILES['postfile']['tmp_name'], $ext);
public static array hex2rgb($color, $default)
| $color | string | 颜色值 | 
| $default | string | 使用无效颜色值时返回的默认颜色 | 
| {return} | array | 由 RGB 三色组成的数组 | 
将 16 进制颜色值转换为 rgb 值
用法:
$color = '#369'; list($r, $g, $b) = Helper_Image::hex2rgb($color); echo "red: {$r}, green: {$g}, blue: {$b}";