php扩展Imagick
<?php
//获取水印图片
logo=newImagick("hacktea8.png");logo=newImagick("hacktea8.png");logo->setImageResolution(0.01,0.03);
//创建一个Imagick对象,同时获取要处理的源图
im=newImagick("www/hacktea8/com.jpg");//获取源图片宽和高im=newImagick("www/hacktea8/com.jpg");//获取源图片宽和高srcWH = im−>getImageGeometry();//图片等比例缩放宽和高设置if(im−>getImageGeometry();//图片等比例缩放宽和高设置if(srcWH['width']>710){
srcW[′width′]=710;srcW[′width′]=710;srcH['height'] = srcW[′width′]/srcW[′width′]/srcWH['width']*srcWH['height']; }else{ $srcW['width'] = $srcWH['width']; $srcH['height'] = $srcWH['height']; } //按照比例进行缩放srcWH['height']; }else{ $srcW['width'] = $srcWH['width']; $srcH['height'] = $srcWH['height']; } //按照比例进行缩放im->thumbnailImage( srcW[′width′],srcW[′width′],srcH['height'], true );
// 按照缩略图大小创建一个有颜色的图片
canvas=newImagick();canvas=newImagick();canvas->newImage( srcW[′width′],srcW[′width′],srcH['height'], 'black', 'jpg' ); //pink,black
//添加水印
im−>compositeImage(im−>compositeImage(logo,Imagick::COMPOSITE_OVER,srcW[′width′]−280,srcW[′width′]−280,srcH['height']-77);
canvas−>setcompressionquality(91);//合并图片canvas−>setcompressionquality(91);//合并图片canvas->compositeImage( im,imagick::COMPOSITEOVER,0,0);//输出图片header("Content−Type:image/jpg");echoim,imagick::COMPOSITEOVER,0,0);//输出图片header("Content−Type:image/jpg");echocanvas;
//生成图片
$canvas->writeImage( "test_img/old_large_img_2_96.jpg" );
?>
imagick是一个功能强大的图像处理库。
strong>
偏置图像:
例子:
<?php
ini_set('display_errors',1);
header('Content-type: image/jpeg');
$image = new Imagick('1.jpg');
$image->rollImage(20,39);
echo $image;
?>
thumbnailImage(width,width,height) 改变图片大小
例子:
<?php
ini_set('display_errors',1);
header('Content-type: image/jpeg');
$image = new Imagick('1.jpg');
$image->thumbnailImage(100,0);
echo $image;
?>
addNoiseImage(int noisetype[,intnoisetype[,intchannel= Imagick::CHANNEL_ALL ]);
功能:
Adds random noise to the image
添加干扰素
Noise constants ( noisetype类型)imagick::NOISEUNIFORM(integer)imagick::NOISEGAUSSIAN(integer)imagick::NOISEMULTIPLICATIVEGAUSSIAN(integer)imagick::NOISEIMPULSE(integer)imagick::NOISELAPLACIAN(integer)imagick::NOISEPOISSON(integer)Channelconstants(noisetype类型)imagick::NOISEUNIFORM(integer)imagick::NOISEGAUSSIAN(integer)imagick::NOISEMULTIPLICATIVEGAUSSIAN(integer)imagick::NOISEIMPULSE(integer)imagick::NOISELAPLACIAN(integer)imagick::NOISEPOISSON(integer)Channelconstants(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)
例子:
<?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 创建文本图像
例子:
<?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(float radius,floatradius,floatsigma [, int $channel ])
Adds blur filter to image 图像模糊度处理
参数:
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)
```php
<?php
ini_set('display_errors',1);
header('Content-type: image/jpeg');
$image = new Imagick('1.jpg');
$image->blurImage(5,3);
echo $image;
?>
borderImage ( mixed bordercolor,intbordercolor,intwidth , int $height ) 图片边框处理
例子:
<?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::CHANNELGREEN);echoimage−>blurImage(5,5,imagick::CHANNELGREEN);echoimage;
?>
charcoalImage ( float radius,floatradius,floatsigma ) 图像素描处理
参数说明:
radius:越小越薄。radius:越小越薄。sigma: 越大 墨越深 反之。
例子:
<?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;
?>
chopImage ( int width,intwidth,intheight , int x,intx,inty )
参数说明:删除一定范围的图像区域
就不做参数说明,一看便知.
colorizeImage( mixed colorize,mixedcolorize,mixedopacity )混合填充颜色
colorize颜色colorize颜色opacit 透明度
例子:
<?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 ( float radius,floatradius,floatsigma )
功能: 返回一个灰度级3D图像 不太好。
例子:
<?php
ini_set('display_errors',1);
header('Content-type: image/jpeg');
$image = new Imagick('1.jpg');
$image->embossImage(1,1);
echo $image;
?>
flipImage(void)
功能: 创建图像倒影(垂直翻转)
例子:
<?php
ini_set('display_errors',1);
header('Content-type: image/jpeg');
$image = new Imagick('1.jpg');
$image->flipImage();
echo $image;
?>
flopImage ( void )
功能: 图像水平横向翻转
<?php
ini_set('display_errors',1);
header('Content-type: image/jpeg');
$image = new Imagick('1.jpg');
$image->flopImage();
echo $image;
?>
frameImage(mixed mattecolor,intmattecolor,intwidth, int height,intheight,intinner_bevel, int outerbevel)功能:创建3D图像边框参数说明:outerbevel)功能:创建3D图像边框参数说明:matte_color:颜色
innerbevel:边框内部倾斜度innerbevel:边框内部倾斜度outer_bevel:外部边框倾斜度
例子:
<?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(宽度)不能小于width(宽度)不能小于inner_bevel(边框内部倾斜度)
Imagick::gammaImage (float gamma[,intgamma[,intchannel= Imagick::CHANNEL_ALL])
功能:调整图像灰度系数
参数说明:
float gamma:灰度系数值gamma:灰度系数值channel 默认为 Imagick::CHANNEL_ALL
Imagick::CHANNEL_ALL
例子 1:
<?php
ini_set('display_errors',1);
header('Content-type: image/jpeg');
$image = new Imagick('1.jpg');
$image->gammaImage(30);
echo $image;
?>
例子 2:
<?php
ini_set('display_errors',1);
header('Content-type: image/jpeg');
$image = new Imagick('1.jpg');
$image->gammaImage(30);
echo $image;
?>
gaussianBlurImage ( float radius,floatradius,floatsigma [, int channel=Imagick::CHANNELALL])功能:高斯模糊处理类似于photo的高斯模糊参数说明:floatchannel=Imagick::CHANNELALL])功能:高斯模糊处理类似于photo的高斯模糊参数说明:floatradius:高斯模糊的半径,像素,不包括中心象素。
float sigma:高斯的标准偏差,以像素为单位。我觉得这个参数最重要。intsigma:高斯的标准偏差,以像素为单位。我觉得这个参数最重要。intchannel :图像颜色模式。
<?php
ini_set('display_errors',1);
header('Content-type: image/jpeg');
$image = new Imagick('1.jpg');
$image->gaussianBlurImage(30,3);
echo $image;
?>
levelImage ( float blackPoint,floatblackPoint,floatgamma , float whitePoint[,intwhitePoint[,intchannel= Imagick::CHANNEL_ALL ] )
功能: 调整图像的色阶(Adjusts the levels of an image)
参数说明
<?php
ini_set('display_errors',1);
header('Content-type: image/jpeg');
$image = new Imagick('1.jpg');
$image->levelImage(4,4,4);
echo $image;
?>
例子2:
<?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( void )
功能说明:简便的图像等比例放大2倍(Is a convenience method that scales an image proportionally to twice its original size. )
例子:
<?php
ini_set('display_errors',1);
header('Content-type: image/jpeg');
$image = new Imagick('1.jpg');
$image->magnifyImage ();
echo $image;
?>
medianFilterImage ( float $radius )
功能:特是的滤镜 有点像photoshop 调色刀滤镜
<?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;
?>
minifyImage(void)
功能:图小缩小一倍(Scales an image proportionally to half its size)
例子:
<?php
ini_set('display_errors',1);
header('Content-type: image/jpeg');
$image = new Imagick('1.jpg');
$image->minifyImage();
echo $image;
?>
modulateImage ( float brightness,floatbrightness,floatsaturation , float hue)功能:控制调整图像的亮度、饱和度、色调。参数说明:floathue)功能:控制调整图像的亮度、饱和度、色调。参数说明:floatbrightness: 亮度
float saturation:饱和度floatsaturation:饱和度floathue 色调
例子1:
<?php
ini_set('display_errors',1);
header('Content-type: image/jpeg');
$image = new Imagick('1.jpg');
$image->modulateImage(100,1,100);
echo $image;
?>
例子2:
<?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,floatradius,floatsigma , float angle[,intangle[,intchannel= Imagick::CHANNEL_DEFAULT ] )
功能:模拟运动模糊(Simulates motion blur) ,类似photoshop的动感模糊滤镜功能
参数说明:
float radius:高斯半径,不包过中心像素。floatradius:高斯半径,不包过中心像素。floatsigma:标准偏差的高斯,以像素为单位。【重要参数】
float angle:模糊角度。intangle:模糊角度。intchannel:图像颜色模式。默认为 Imagick::CHANNEL_DEFAULT
例子1:
<?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;
?>
例子2:
<?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 ( float $radius ):
功能说明: 模拟油画滤镜(Simulates an oil painting)
例子:
<?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 ( float angle[,intangle[,intchannel= Imagick::CHANNEL_ALL ] )
功能: 径向模糊(Radial blurs an image)
<?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 ( int width,intwidth,intheight , int x,intx,inty , bool $raise )
功能说明:创建3D图像按钮(Creates a simulated 3d button-like effect)
<?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;
?>
本文地址:https://blog.csdn.net/wangzhae/article/details/107380063
上一篇: RestFull风格及响应状态码
下一篇: 朱祁镇上台后,朱祁钰的后妃们下场有多惨?