偏置图像
1 2 3 4 5 6 7 |
<?php ini_set('display_errors',1); header('Content-type: image/jpeg'); $image = new Imagick('1.jpg'); $image->rollImage(20,39); echo $image; ?> |
thumbnailImage($width,$height) 改变图片大小
1 2 3 4 5 6 7 |
<?php ini_set('display_errors',1); header('Content-type: image/jpeg'); $image = new Imagick('1.jpg'); $image->thumbnailImage(100,0); echo $image; ?> |
addNoiseImage 添加干扰素
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
Noise constants ( $noise_type 类型) imagick::NOISE_UNIFORM (integer) imagick::NOISE_GAUSSIAN (integer) imagick::NOISE_MULTIPLICATIVEGAUSSIAN (integer) imagick::NOISE_IMPULSE (integer) imagick::NOISE_LAPLACIAN (integer) imagick::NOISE_POISSON (integer) Channel constants ( $channel 类型) imagick::CHANNEL_UNDEFINED (integer) imagick::CHANNEL_RED (integer) imagick::CHANNEL_GRAY (integer) imagick::CHANNEL_CYAN (integer) imagick::CHANNEL_GREEN (integer) imagick::CHANNEL_MAGENTA (integer) imagick::CHANNEL_BLUE (integer) imagick::CHANNEL_YELLOW (integer) imagick::CHANNEL_ALPHA (integer) imagick::CHANNEL_OPACITY (integer) imagick::CHANNEL_MATTE (integer) imagick::CHANNEL_BLACK (integer) imagick::CHANNEL_INDEX (integer) imagick::CHANNEL_ALL (integer) <pre> <pre lang="php"> <?php ini_set('display_errors',1); header('Content-type: image/jpeg'); $image = new Imagick('1.jpg'); $image->thumbnailImage(100,0); $image->addNoiseImage(imagick::NOISE_POISSON,imagick::CHANNEL_OPACITY); echo $image; ?> |
annotateImage 创建文本图像
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?php $image = new Imagick(); $draw = new ImagickDraw(); $pixel = new ImagickPixel( 'gray' ); $image->newImage(800, 75, $pixel); $pixel->setColor('black'); $draw->setFont('Bookman-DemiItalic'); $draw->setFontSize( 30 ); $image->annotateImage($draw, 10, 45, 0, 'The quick brown fox jumps over the lazy dog'); $image->setImageFormat('png'); header('Content-type: image/png'); echo $image; ?> |
blurImage 图像模糊度处理
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
int $channel : imagick::CHANNEL_UNDEFINED (integer) imagick::CHANNEL_RED (integer) imagick::CHANNEL_GRAY (integer) imagick::CHANNEL_CYAN (integer) imagick::CHANNEL_GREEN (integer) imagick::CHANNEL_MAGENTA (integer) imagick::CHANNEL_BLUE (integer) imagick::CHANNEL_YELLOW (integer) imagick::CHANNEL_ALPHA (integer) imagick::CHANNEL_OPACITY (integer) imagick::CHANNEL_MATTE (integer) imagick::CHANNEL_BLACK (integer) imagick::CHANNEL_INDEX (integer) imagick::CHANNEL_ALL (integer) |
1 2 3 4 5 6 7 |
<?php ini_set('display_errors',1); header('Content-type: image/jpeg'); $image = new Imagick('1.jpg'); $image->blurImage(5,3); echo $image; ?> |
borderImage 图片边框处理
1 2 3 4 5 6 7 8 9 10 11 |
<?php ini_set('display_errors',1); header('Content-type: image/jpeg'); $image = new Imagick('1.jpg'); $color=new ImagickPixel(); $color->setColor("rgb(220,220,220)"); $image->borderImage($color,5,4); $image->blurImage(5,5,imagick::CHANNEL_GREEN); echo $image; ?> |
charcoalImage ( float $radius , float $sigma ) 图像素描处理
参数说明:
$radius :越小越薄。
$sigma: 越大 墨越深 反之。
1 2 3 4 5 6 7 8 9 10 11 |
<?php ini_set('display_errors',1); header('Content-type: image/jpeg'); $image = new Imagick('1.jpg'); $color=new ImagickPixel(); $color->setColor("rgb(220,220,220)"); $image->borderImage($color,5,4); $image->charcoalImage(0.0001,0.001); //$image->blurImage(5,5,imagick::CHANNEL_GREEN); echo $image; ?> |
borderImage 图片边框处理
1 2 3 4 5 6 7 8 9 10 11 |
<?php ini_set('display_errors',1); header('Content-type: image/jpeg'); $image = new Imagick('1.jpg'); $color=new ImagickPixel(); $color->setColor("rgb(220,220,220)"); $image->borderImage($color,5,4); $image->blurImage(5,5,imagick::CHANNEL_GREEN); echo $image; ?> |
colorizeImage( mixed $colorize , mixed $opacity )混合填充颜色
$colorize 颜色
$opacit 透明度
1 2 3 4 5 6 7 8 9 10 11 |
<?php /* 胶卷底片效果 */ ini_set('display_errors',1); header('Content-type: image/jpeg'); $image = new Imagick('1.jpg'); $image->negateImage(false); $image->colorizeImage('#000',1.0); echo $image; ?> |
embossImage 返回一个灰度级3D图像
1 2 3 4 5 6 7 |
<?php ini_set('display_errors',1); header('Content-type: image/jpeg'); $image = new Imagick('1.jpg'); $image->embossImage(1,1); echo $image; ?> |
flipImage 创建图像倒影(垂直翻转)
1 2 3 4 5 6 7 |
<?php ini_set('display_errors',1); header('Content-type: image/jpeg'); $image = new Imagick('1.jpg'); $image->flipImage(); echo $image; ?> |
flopImage 图像水平横向翻转
1 2 3 4 5 6 7 |
<?php ini_set('display_errors',1); header('Content-type: image/jpeg'); $image = new Imagick('1.jpg'); $image->flopImage(); echo $image; ?> |
frameImage(mixed $matte_color,int $width, int $height,int $inner_bevel, int $outer_bevel) 创建3D图像边框
参数说明:
$matte_color:颜色
$inner_bevel:边框内部倾斜度
$outer_bevel:外部边框倾斜度
1 2 3 4 5 6 7 8 9 |
<?php ini_set('display_errors',1); header('Content-type: image/jpeg'); $image = new Imagick('1.jpg'); $color=new ImagickPixel(); $color->setColor("rgb(220,220,220)"); $image->frameImage($color,11,11,1,10); echo $image; ?> |
注意事项:
$width(宽度)不能小于$inner_bevel(边框内部倾斜度)
Imagick::gammaImage (float $gamma [,int $channel= Imagick::CHANNEL_ALL])调整图像灰度系数
参数说明:
float $gamma :灰度系数值
$channel 默认为 Imagick::CHANNEL_ALL
Imagick::CHANNEL_ALL
1 2 3 4 5 6 7 |
<?php ini_set('display_errors',1); header('Content-type: image/jpeg'); $image = new Imagick('1.jpg'); $image->gammaImage(30); echo $image; ?> |
gaussianBlurImage ( float $radius , float $sigma [, int $channel= Imagick::CHANNEL_ALL ] ) 高斯模糊处理 类似于photo的高斯模糊
参数说明:
float $radius:高斯模糊的半径,像素,不包括中心象素。
float $sigma :高斯的标准偏差,以像素为单位。我觉得这个参数最重要。
int $channel :图像颜色模式。
1 2 3 4 5 6 7 |
<?php ini_set('display_errors',1); header('Content-type: image/jpeg'); $image = new Imagick('1.jpg'); $image->gaussianBlurImage(30,3); echo $image; ?> |
levelImage 调整图像的色阶
1 2 3 4 5 6 7 |
<?php ini_set('display_errors',1); header('Content-type: image/jpeg'); $image = new Imagick('1.jpg'); $image->levelImage(4,4,4); echo $image; ?> |
1 2 3 4 5 6 7 8 |
<?php <?php ini_set('display_errors',1); header('Content-type: image/jpeg'); $image = new Imagick('1.jpg'); $image->levelImage(200,200,200,imagick::CHANNEL_GREEN); echo $image; ?> |
magnifyImage 简便的图像等比例放大2倍
1 2 3 4 5 6 7 |
<?php ini_set('display_errors',1); header('Content-type: image/jpeg'); $image = new Imagick('1.jpg'); $image->magnifyImage (); echo $image; ?> |
minifyImage 简便的图像等比例缩小一倍
1 2 3 4 5 6 7 |
<?php ini_set('display_errors',1); header('Content-type: image/jpeg'); $image = new Imagick('1.jpg'); $image->minifyImage(); echo $image; ?> |
medianFilterImage 有点像photoshop 调色刀滤镜
1 2 3 4 5 6 7 8 9 |
<?php ini_set('display_errors',1); header('Content-type: image/jpeg'); $image = new Imagick('1.jpg'); $color=new ImagickPixel(); $color->setColor("rgb(220,220,220)"); $image->medianFilterImage(5); echo $image; ?> |
modulateImage ( float $brightness , float $saturation , float $hue ) 控制调整图像的 亮度、饱和度、色调
参数说明:
float $brightness: 亮度
float $saturation :饱和度
float $hue 色调
1 2 3 4 5 6 7 |
<?php ini_set('display_errors',1); header('Content-type: image/jpeg'); $image = new Imagick('1.jpg'); $image->modulateImage(100,1,100); echo $image; ?> |
1 2 3 4 5 6 7 |
<?php ini_set('display_errors',1); header('Content-type: image/jpeg'); $image = new Imagick('1.jpg'); $image->modulateImage(250,1,250); echo $image; ?> |
motionBlurImagemotionBlurImage ( float $radius , float $sigma , float $angle [, int $channel= Imagick::CHANNEL_DEFAULT ] ) 模拟运动模糊
参数说明:
float $radius: 高斯 半径,不包过中心像素。
float $sigma:标准偏差的高斯,以像素为单位。【重要参数】
float $angle:模糊角度。
int $channel:图像颜色模式。默认为 Imagick::CHANNEL_DEFAULT
1 2 3 4 5 6 7 8 9 |
<?php ini_set('display_errors',1); header('Content-type: image/jpeg'); $image = new Imagick('1.jpg'); $color=new ImagickPixel(); $color->setColor("rgb(220,220,220)"); $image->motionBlurImage (61,10,10); echo $image; ?> |
1 2 3 4 5 6 7 8 9 |
<?php ini_set('display_errors',1); header('Content-type: image/jpeg'); $image = new Imagick('1.jpg'); $color=new ImagickPixel(); $color->setColor("rgb(220,220,220)"); $image->motionBlurImage (201,10,100); echo $image; ?> |
oilPaintImage 模拟油画滤镜
1 2 3 4 5 6 7 8 9 |
<?php ini_set('display_errors',1); header('Content-type: image/jpeg'); $image = new Imagick('1.jpg'); $color=new ImagickPixel(); $color->setColor("rgb(220,220,220)"); $image->oilPaintImage(1); echo $image; ?> |
radialBlurImage 径向模糊
1 2 3 4 5 6 7 8 9 |
<?php ini_set('display_errors',1); header('Content-type: image/jpeg'); $image = new Imagick('1.jpg'); $color=new ImagickPixel(); $color->setColor("rgb(220,220,220)"); $image->radialBlurImage(30); echo $image; ?> |
raiseImage 创建3D图像按钮
1 2 3 4 5 6 7 8 9 |
<?php ini_set('display_errors',1); header('Content-type: image/jpeg'); $image = new Imagick('1.jpg'); $color=new ImagickPixel(); $color->setColor("rgb(220,220,220)"); $image->raiseImage(10,10,3,5,6); echo $image; ?> |
处理图片水印
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
<?php //获取水印图片 $logo = new Imagick("logo.png"); $logo->setImageResolution(0.01,0.03); //创建一个Imagick对象,同时获取要处理的源图 $im = new Imagick( "old_large_img_2.jpg" ); //获取源图片宽和高 $srcWH = $im->getImageGeometry(); //图片等比例缩放宽和高设置 if($srcWH['width']>710){ $srcW['width'] = 710; $srcH['height'] = $srcW['width']/$srcWH['width']*$srcWH['height']; }else{ $srcW['width'] = $srcWH['width']; $srcH['height'] = $srcWH['height']; } //按照比例进行缩放 $im->thumbnailImage( $srcW['width'], $srcH['height'], true ); // 按照缩略图大小创建一个有颜色的图片 $canvas = new Imagick(); $canvas->newImage( $srcW['width'], $srcH['height'], 'black', 'jpg' ); //pink,black //添加水印 $im->compositeImage($logo,Imagick::COMPOSITE_OVER,$srcW['width']-280,$srcH['height']-77); $canvas->setcompressionquality(91); //合并图片 $canvas->compositeImage( $im, imagick::COMPOSITE_OVER, 0, 0); //输出图片 header( "Content-Type: image/jpg" ); echo $canvas; //生成图片 $canvas->writeImage( "test_img/1.jpg" ); ?> |