<?php // Plug-in 14: Image Alter
// This is an executable example with additional code supplied
// To obtain just the plug-ins please click on the Download link
// You'll need a jpeg image file called photo.jpg in this folder
$image = imagecreatefromjpeg("photo.jpg");
$copy = PIPHP_ImageAlter($image, 12);
imagejpeg($copy, "photo2.jpg");
echo "<img src='photo.jpg' align=left><img src='photo2.jpg'>";
function PIPHP_ImageAlter($image, $effect)
{
// Plug-in 14: Image Alter
//
// This plug-in takes a GD image and modifies it
// according to the selected effect. The arguments required
// are:
//
// $image: The image source
// $effect: The effect to use between 1 and 14:
// 1 = Sharpen
// 2 = Blur
// 3 = Brighten
// 4 = Darken
// 5 = Increase Contrast
// 6 = Decrease Contrast
// 7 = Grayscale
// 8 = Invert
// 9 = Increase Red
// 10 = Increase Green
// 11 = Increase Blue
// 12 = Edge Detect
// 13 = Emboss
// 14 = Sketchify
switch($effect)
{
case 1: imageconvolution($image, array(array(-1, -1, -1),
array(-1, 16, -1), array(-1, -1, -1)), 8, 0);
break;
case 2: imagefilter($image,
IMG_FILTER_GAUSSIAN_BLUR); break;
case 3: imagefilter($image,
IMG_FILTER_BRIGHTNESS, 20); break;
case 4: imagefilter($image,
IMG_FILTER_BRIGHTNESS, -20); break;
case 5: imagefilter($image,
IMG_FILTER_CONTRAST, -20); break;
case 6: imagefilter($image,
IMG_FILTER_CONTRAST, 20); break;
case 7: imagefilter($image,
IMG_FILTER_GRAYSCALE); break;
case 8: imagefilter($image,
IMG_FILTER_NEGATE); break;
case 9: imagefilter($image,
IMG_FILTER_COLORIZE, 128, 0, 0, 50); break;
case 10: imagefilter($image,
IMG_FILTER_COLORIZE, 0, 128, 0, 50); break;
case 11: imagefilter($image,
IMG_FILTER_COLORIZE, 0, 0, 128, 50); break;
case 12: imagefilter($image,
IMG_FILTER_EDGEDETECT); break;
case 13: imagefilter($image,
IMG_FILTER_EMBOSS); break;
case 14: imagefilter($image,
IMG_FILTER_MEAN_REMOVAL); break;
}
return $image;
}
?>
插件说明:
插件14接受一个需要变换的图像和处理要求,具体是:
$image 需要变换的GD图像。
$effect 变换效果,去1~14之间的某个值,如表所示:
$effect | 效果(英文) | 效果(中文) |
---|---|---|
1 | Sharpen | 锐化 |
2 | Blur | 模糊 |
3 | Brighten | 增亮 |
4 | Darken | 变暗 |
5 | Increase contrast | 增加对比度 |
6 | Decrease contrast | 减小对比度 |
7 | Grayscale | 灰度值 |
8 | Invert | 反转 |
9 | Increase red | 增加红色分量 |
10 | Increase green | 增加绿色分量 |
11 | Increase blue | 增加蓝色分量 |
12 | Edge detect | 边缘检测 |
13 | Emboss | 浮雕化 |
14 | Sketchify | 素描 |