很久以前写的代码了,现在才想起贴上来. 稍微更改并结合人脸识别可以实现自动模糊人物的脸部.
<?php
require_once 'RGB.php'; //这里请看另一个 "PHP实现色彩空间转换"
/**
* 图像信息处理
* @author shizhuolin
*/
class Image {
/**
* 位图资源
* @var resource
*/
protected $_image;
/**
* 使用指定文件构造图像操作实例
* @param string $filename
*/
public function __construct($filename=null) {
if ($filename)
$this->open($filename);
}
/**
* 读取指定文件明的图像
* @param string $filename
* @return Image
*/
public function open($filename) {
$handle = fopen($filename, "rb");
$contents = stream_get_contents($handle);
fclose($handle);
$image = imagecreatefromstring($contents);
$width = imagesx($image);
$height = imagesy($image);
$truecolorimage = imagecreatetruecolor($width, $height);
imagefilledrectangle($truecolori