使用Imagick绘图 文字换行 生成二维码例子

Imagick是一个可以供PHP调用ImageMagick功能的PHP扩展了,这个插件比gd库的功能还要强大了,我们下文来看使用Imagick绘图 文字换行 生成二维码例子,希望例子能够对各位有帮助.

二维码的生成使用的QRcode库:http://phpqrcode.sourceforge.net/

感觉最烦的就是文字的换行了,处理函数来源于网络,下面代码中的使用的函数不完整,完整代码上传 github 了:https://github.com/zhoumengkang/imagick-demo

模板图和效果图如下:

Imagick 绘图,文字换行,生成二维码:

  1. function createUserCard($username,$num,$desc,$id,$url){
  2. //error_reporting(E_ALL);
  3. //ini_set("display_errors","On");
  4. // 新建一个空白图片用来做画布
  5. $canvas = new Imagick;
  6. $canvasWidth = 588;
  7. $canvasHeight = 684;
  8. $canvas->newimage($canvasWidth, $canvasHeight, 'white');
  9. $canvas->setImageFormat('jpg');
  10. $fontFile = FONT_PATH."/msyh.ttf";
  11. $fontSize = 20;
  12. // 封面
  13. $face = new Imagick();
  14. $face->readimageblob(curl_get($url)); // 读取 url 里面的图片
  15. $face->cropThumbnailImage(200, 200);
  16. // 读取图片
  17. $pic = new Imagick;
  18. $QRcodeFile = createQRcode($id,"m");
  19. $pic->readImage($QRcodeFile);
  20. $codeWith = 256;
  21. $pic->cropThumbnailImage($codeWith, $codeWith);
  22. // 背景图片
  23. $background = new Imagick;
  24. $background->readimage("/data0/logs/static/user/template.png");
  25. // 将图片合并到画布
  26. $canvas->compositeImage($face, Imagick::COMPOSITE_OVER, 194, 0);
  27. $canvas->compositeImage($pic, Imagick::COMPOSITE_OVER, ($canvasWidth-$codeWith)/2, $canvasHeight-$codeWith-31);
  28. $canvas->compositeImage($background, Imagick::COMPOSITE_OVER, 0, 0);
  29. $draw = new ImagickDraw;
  30. $draw->setFont($fontFile);
  31. $draw->setFontSize($fontSize);
  32. $draw->setFillColor(new ImagickPixel('#000000'));
  33. $draw->setTextAlignment(Imagick::ALIGN_CENTER);
  34. $canvas->annotateImage($draw,$canvasWidth/2, 230,0,$username);
  35. $desc = autowrap($fontSize,$fontFile,$desc,460);
  36. $draw->setFont($fontFile);
  37. $draw->setFontSize($fontSize);
  38. $draw->setFillColor(new ImagickPixel('#000000'));
  39. $draw->setTextAlignment(Imagick::ALIGN_CENTER);
  40. $canvas->annotateImage($draw,$canvasWidth/2, 310,0,$desc);
  41. $draw->setFont($fontFile);
  42. $draw->setFontSize($fontSize);
  43. $draw->setFillColor(new ImagickPixel('#E23B3B'));
  44. $draw->setTextAlignment(Imagick::ALIGN_LEFT);
  45. $canvas->annotateImage($draw,290, 275,0,$num);
  46. $draw->setFont($fontFile);
  47. $draw->setFontSize($fontSize);
  48. $draw->setFillColor(new ImagickPixel('#ffffff'));
  49. $draw->setTextAlignment(Imagick::ALIGN_CENTER);
  50. $canvas->annotateImage($draw,$canvasWidth/2, $canvasHeight-20,0,"来找我玩,先长按识别二维码");
  51. //phpfensi.com
  52. // 保存图片到另一目录
  53. $userCardPath = "/data0/logs/static/user";
  54. $canvas->writeimage($userCardPath ."/".$id.".jpg");
  55. }
  56. createUserCard("周梦康",6376,"JR 史密斯搞什么鬼最后一分钟才爆发, 要爆发你丫早点啊,总冠军送人了吧",2,"http://f10.topitme.com/l/201005/17/12740893805467.jpg");

例子2:

  1. $towidth = '500';
  2. $toheight = '700'; //设置图片调整大小时允许的最大宽度和高度
  3. $sourcefile = './b.jpg'; //定义一个图像文件路径
  4. //$image->writeImage('./b.jpg.bak'); //可以备份这个图片
  5. $myimage = new Imagick( $sourcefile ); //读入该图像文件
  6. $exifobject = my_exif( $myimage ); //自写函数,读取exif信息(拍摄数据),按自己的要求排列exif信息,返回对象
  7. //$myimage->setImageFormat('jpeg'); //把图片转为jpg格式
  8. $myimage->setCompressionQuality( 100 ); //设置jpg压缩质量,1 - 100
  9. $myimage->enhanceImage(); //去噪点
  10. $sourcewidth = $myimage->getImageWidth(); //获取读入图像原始大小
  11. if ( $sourcewidth > $towidth )
  12. {
  13. $myimage->scaleImage( $towidth, $toheight, true ); //调整图片大小
  14. }
  15. $myimage->raiseImage( 8, 8, 0, 0, 1 ); //加半透明边框
  16. $resizewidth = $myimage->getImageWidth(); //读出调整之后的图片大小
  17. $resizeheight = $myimage->getImageHeight();
  18. $drawback = new ImagickDraw(); //实例化一个绘画对象,绘制半透明黑色背景给exif信息用
  19. $drawback->setFillColor( new ImagickPixel('#000000') ); //设置填充颜色为黑色
  20. $drawback->setFillOpacity( 0.6 ); //填充透明度为0.6,参数0.1-1,1为不透明
  21. $drawback->rectangle( $resizewidth / 2 - 190, $resizeheight - 50, $resizewidth / 2 + 190, $resizeheight - 12 ); //绘制矩形参数,分别为左上角x、y,右下角x、y
  22. $myimage->drawImage( $drawback ); //确认到image中绘制该矩形框
  23. $draw = new ImagickDraw(); //实例化一个绘画对象,绘制exif文本信息嵌入图片中
  24. $draw->setFont( './xianhei.ttf' ); //设置文本字体,要求ttf或者ttc字体,可以绝对或者相对路径
  25. $draw->setFontSize( 11 ); //设置字号
  26. $draw->setTextAlignment( 2 ); //文字对齐方式,2为居中
  27. $draw->setFillColor( '#FFFFFF' ); //文字填充颜色
  28. $myimage->annotateImage( $draw, $resizewidth / 2, $resizeheight - 39, 0, $exifobject->row1 ); //绘制第一行文本,居中
  29. $myimage->annotateImage( $draw, $resizewidth / 2, $resizeheight - 27, 0, $exifobject->row2 ); //绘制第二行文本,居中
  30. $myimage->annotateImage( $draw, $resizewidth / 2, $resizeheight - 15, 0, $exifobject->row3 ); //绘制第三行文本,居中
  31. /* Output the image with headers */
  32. header( 'Content-type: image/jpeg' ); //php文件输出mime类型为jpeg图片
  33. echo $myimage; //在当前php页面输出图片
  34. //$image->writeImage('./b.new.jpg'); //如果图片不需要在当前php程序中输出,使用写入图片到磁盘函数,上面的设置header也可以去除
  35. $myimage->clear();
  36. $myimage->destroy(); //释放资源
  37. //自写函数,读取exif信息,返回对象
  38. function my_exif( $myimage )
  39. {
  40. $exifArray = array( 'exif:Model' => '未知', 'exif:DateTimeOriginal' => '未知', 'exif:ExposureProgram' => '未知', 'exif:FNumber' => '0/10', 'exif:ExposureTime' => '0/10', 'exif:ISOSpeedRatings' => '未知',
  41. 'exif:MeteringMode' => '未知', 'exif:Flash' => '关闭闪光灯', 'exif:FocalLength' => '未知', 'exif:ExifImageWidth' => '未知', 'exif:ExifImageLength' => '未知' ); //初始化部分信息,防止无法读取照片exif信息时运算发生错误
  42. $exifArray = $myimage->getImageProperties( "exif:*" ); //读取图片的exif信息,存入$exifArray数组
  43. //如果需要显示原数组可以使用print_r($exifArray);
  44. $r->row1 = '相机:' . $exifArray['exif:Model'];
  45. $r->row1 = $r->row1 . ' 拍摄时间:' . $exifArray['exif:DateTimeOriginal'];
  46. switch ( $exifArray['exif:ExposureProgram'] )
  47. {
  48. case 1:
  49. $exifArray['exif:ExposureProgram'] = "手动(M)";
  50. break; //Manual Control
  51. case 2:
  52. $exifArray['exif:ExposureProgram'] = "程序自动(P)";
  53. break; //Program Normal
  54. case 3:
  55. $exifArray['exif:ExposureProgram'] = "光圈优先(A,Av)";
  56. break; //Aperture Priority
  57. case 4:
  58. $exifArray['exif:ExposureProgram'] = "快门优先(S,Tv)";
  59. break; //Shutter Priority
  60. case 5:
  61. $exifArray['exif:ExposureProgram'] = "慢速快门";
  62. break; //Program Creative (Slow Program)
  63. case 6:
  64. $exifArray['exif:ExposureProgram'] = "运动模式";
  65. break; //Program Action(High-Speed Program)
  66. case 7:
  67. $exifArray['exif:ExposureProgram'] = "人像";
  68. break; //Portrait
  69. case 8:
  70. $exifArray['exif:ExposureProgram'] = "风景";
  71. break; //Landscape
  72. default:
  73. $exifArray['exif:ExposureProgram'] = "其它";
  74. }
  75. $r->row1 = $r->row1 . ' 模式:' . $exifArray['exif:ExposureProgram'];
  76. $exifArray['exif:FNumber'] = explode( '/', $exifArray['exif:FNumber'] );
  77. $exifArray['exif:FNumber'] = $exifArray['exif:FNumber'][0] / $exifArray['exif:FNumber'][1];
  78. $r->row2 = '光圈:F/' . $exifArray['exif:FNumber'];
  79. $exifArray['exif:ExposureTime'] = explode( '/', $exifArray['exif:ExposureTime'] );
  80. if ( ($exifArray['exif:ExposureTime'][0] / $exifArray['exif:ExposureTime'][1]) >= 1 )
  81. {
  82. $exifArray['exif:ExposureTime'] = sprintf( "%.1fs", (float)$exifArray['exif:ExposureTime'][0] / $exifArray['exif:ExposureTime'][1] );
  83. } else
  84. {
  85. $exifArray['exif:ExposureTime'] = sprintf( "1/%ds", $exifArray['exif:ExposureTime'][1] / $exifArray['exif:ExposureTime'][0] );
  86. }
  87. $r->row2 = $r->row2 . ' 快门:' . $exifArray['exif:ExposureTime'];
  88. $r->row2 = $r->row2 . ' ISO:' . $exifArray['exif:ISOSpeedRatings'];
  89. $exifArray['exif:ExposureBiasValue'] = explode( "/", $exifArray['exif:ExposureBiasValue'] );
  90. $exifArray['exif:ExposureBiasValue'] = sprintf( "%1.1feV", ((float)$exifArray['exif:ExposureBiasValue'][0] / $exifArray['exif:ExposureBiasValue'][1] * 100) / 100 );
  91. if ( (float)$exifArray['exif:ExposureBiasValue'] > 0 )
  92. {
  93. $exifArray['exif:ExposureBiasValue'] = "+" . $exifArray['exif:ExposureBiasValue'];
  94. }
  95. $r->row2 = $r->row2 . ' 补偿:' . $exifArray['exif:ExposureBiasValue'];
  96. switch ( $exifArray['exif:MeteringMode'] )
  97. {
  98. case 0:
  99. $exifArray['exif:MeteringMode'] = "未知";
  100. break;
  101. case 1:
  102. $exifArray['exif:MeteringMode'] = "矩阵";
  103. break;
  104. case 2:
  105. $exifArray['exif:MeteringMode'] = "中央重点平均";
  106. break;
  107. case 3:
  108. $exifArray['exif:MeteringMode'] = "点测光";
  109. break;
  110. case 4:
  111. $exifArray['exif:MeteringMode'] = "多点测光";
  112. break;
  113. default:
  114. $exifArray['exif:MeteringMode'] = "其它";
  115. }
  116. $r->row2 = $r->row2 . ' 测光:' . $exifArray['exif:MeteringMode'];
  117. switch ( $exifArray['exif:Flash'] )
  118. {
  119. case 1:
  120. $exifArray['exif:Flash'] = "开启闪光灯";
  121. break;
  122. }
  123. $r->row2 = $r->row2 . ' ' . $exifArray['exif:Flash'];
  124. if ( $exifArray['exif:FocalLengthIn35mmFilm'] )
  125. {
  126. $r->row3 = '等效焦距:' . $exifArray['exif:FocalLengthIn35mmFilm'] . "mm";
  127. } else
  128. {
  129. $exifArray['exif:FocalLength'] = explode( "/", $exifArray['exif:FocalLength'] );
  130. $exifArray['exif:FocalLength'] = sprintf( "%4.1fmm", (double)$exifArray['exif:FocalLength'][0] / $exifArray['exif:FocalLength'][1] );
  131. $r->row3 = '焦距:' . $exifArray['exif:FocalLength'];
  132. }
  133. $r->row3 = $r->row3 . ' 原始像素:' . $exifArray['exif:ExifImageWidth'] . 'x' . $exifArray['exif:ExifImageLength'] . 'px';
  134. if ( $exifArray['exif:Software'] )
  135. {
  136. $r->row3 = $r->row3 . ' 后期:' . $exifArray['exif:Software'];
  137. }
  138. return $r;
  139. }

例子3:

  1. <?php
  2. //获取水印图片
  3. $logo = new Imagick("logo.png");
  4. $logo->setImageResolution(0.01,0.03);
  5. //创建一个Imagick对象,同时获取要处理的源图
  6. $im = new Imagick( "old_large_img_2.jpg" );
  7. //获取源图片宽和高
  8. $srcWH = $im->getImageGeometry();
  9. //图片等比例缩放宽和高设置
  10. if($srcWH['width']>710){
  11. $srcW['width'] = 710;
  12. $srcH['height'] = $srcW['width']/$srcWH['width']*$srcWH['height'];
  13. }else{
  14. $srcW['width'] = $srcWH['width'];
  15. $srcH['height'] = $srcWH['height'];
  16. }
  17. //按照比例进行缩放
  18. $im->thumbnailImage( $srcW['width'], $srcH['height'], true );
  19. // 按照缩略图大小创建一个有颜色的图片
  20. $canvas = new Imagick();
  21. $canvas->newImage( $srcW['width'], $srcH['height'], 'black', 'jpg' ); //pink,black
  22. //添加水印
  23. $im->compositeImage($logo,Imagick::COMPOSITE_OVER,$srcW['width']-280,$srcH['height']-77);
  24. $canvas->setcompressionquality(91);
  25. //合并图片
  26. $canvas->compositeImage( $im, imagick::COMPOSITE_OVER, 0, 0);
  27. //输出图片
  28. header( "Content-Type: image/jpg" );
  29. echo $canvas;
  30. //生成图片
  31. $canvas->writeImage( "test_img/old_large_img_2_96.jpg" );
  32. ?>

imagick是一个功能强大的图像处理库。

说是翻译 其实就是简要介绍imagick 的主要功能的或者说是我觉得比较实用的功能函数的介绍 以及使用的例子。

因为本人的英语水平有限,所以采用比较通俗或者说比较贴近应用化的语言来描述。

先欣赏一组炫丽的效果:

偏置图像:

例子:

  1. <?php
  2. ini_set('display_errors',1);
  3. header('Content-type: image/jpeg');
  4. $image = new Imagick('1.jpg');
  5. $image->rollImage(20,39);
  6. echo $image;
  7. ?>

thumbnailImage($width,$height) 改变图片大小

例子:

  1. <?php
  2. ini_set('display_errors',1);
  3. header('Content-type: image/jpeg');
  4. $image = new Imagick('1.jpg');
  5. $image->thumbnailImage(100,0);
  6. echo $image;
  7. ?>
  8. addNoiseImage(int $noise_type [, int $channel= Imagick::CHANNEL_ALL ]);

功能:Adds random noise to the image

添加干扰素:

  1. Noise constants ( $noise_type 类型)
  2. imagick::NOISE_UNIFORM (integer)
  3. imagick::NOISE_GAUSSIAN (integer)
  4. imagick::NOISE_MULTIPLICATIVEGAUSSIAN (integer)
  5. imagick::NOISE_IMPULSE (integer)
  6. imagick::NOISE_LAPLACIAN (integer)
  7. imagick::NOISE_POISSON (integer)
  8. Channel constants ( $channel 类型)
  9. imagick::CHANNEL_UNDEFINED (integer)
  10. imagick::CHANNEL_RED (integer)
  11. imagick::CHANNEL_GRAY (integer)
  12. imagick::CHANNEL_CYAN (integer)
  13. imagick::CHANNEL_GREEN (integer)
  14. imagick::CHANNEL_MAGENTA (integer)
  15. imagick::CHANNEL_BLUE (integer)
  16. imagick::CHANNEL_YELLOW (integer)
  17. imagick::CHANNEL_ALPHA (integer)
  18. imagick::CHANNEL_OPACITY (integer)
  19. imagick::CHANNEL_MATTE (integer)
  20. imagick::CHANNEL_BLACK (integer)
  21. imagick::CHANNEL_INDEX (integer)
  22. imagick::CHANNEL_ALL (integer)

例子:

  1. <?php
  2. ini_set('display_errors',1);
  3. header('Content-type: image/jpeg');
  4. $image = new Imagick('1.jpg');
  5. $image->thumbnailImage(100,0);
  6. $image->addNoiseImage(imagick::NOISE_POISSON,imagick::CHANNEL_OPACITY);
  7. echo $image;
  8. ?>

annotateImage 创建文本图像

例子:

  1. <?php
  2. $image = new Imagick();
  3. $draw = new ImagickDraw();
  4. $pixel = new ImagickPixel( 'gray' );
  5. $image->newImage(800, 75, $pixel);
  6. $pixel->setColor('black');
  7. $draw->setFont('Bookman-DemiItalic');
  8. $draw->setFontSize( 30 );
  9. $image->annotateImage($draw, 10, 45, 0, 'The quick brown fox jumps over the lazy dog');
  10. $image->setImageFormat('png');
  11. header('Content-type: image/png');
  12. echo $image;
  13. ?>
  14. blurImage(float $radius , float $sigma [, int $channel ])

Adds blur filter to image 图像模糊度处理

参数:

  1. int $channel :
  2. imagick::CHANNEL_UNDEFINED (integer)
  3. imagick::CHANNEL_RED (integer)
  4. imagick::CHANNEL_GRAY (integer)
  5. imagick::CHANNEL_CYAN (integer)
  6. imagick::CHANNEL_GREEN (integer)
  7. imagick::CHANNEL_MAGENTA (integer)
  8. imagick::CHANNEL_BLUE (integer)
  9. imagick::CHANNEL_YELLOW (integer)
  10. imagick::CHANNEL_ALPHA (integer)
  11. imagick::CHANNEL_OPACITY (integer)
  12. imagick::CHANNEL_MATTE (integer)
  13. imagick::CHANNEL_BLACK (integer)
  14. imagick::CHANNEL_INDEX (integer)
  15. imagick::CHANNEL_ALL (integer)
  16. <?php
  17. ini_set('display_errors',1);
  18. header('Content-type: image/jpeg');
  19. $image = new Imagick('1.jpg');
  20. $image->blurImage(5,3);
  21. echo $image;
  22. ?>

borderImage ( mixed $bordercolor , int $width , int $height ) 图片边框处理

例子:

  1. <?php
  2. ini_set('display_errors',1);
  3. header('Content-type: image/jpeg');
  4. $image = new Imagick('1.jpg');
  5. $color=new ImagickPixel();
  6. $color->setColor("rgb(220,220,220)");
  7. $image->borderImage($color,5,4);
  8. $image->blurImage(5,5,imagick::CHANNEL_GREEN);
  9. echo $image;
  10. ?>

charcoalImage ( float $radius , float $sigma ) 图像素描处理

参数说明:

$radius:越小越薄。

$sigma:越大 墨越深 反之。

例子:

  1. <?php
  2. ini_set('display_errors',1);
  3. header('Content-type: image/jpeg');
  4. $image = new Imagick('1.jpg');
  5. $color=new ImagickPixel();
  6. $color->setColor("rgb(220,220,220)");
  7. $image->borderImage($color,5,4);
  8. $image->charcoalImage(0.0001,0.001);
  9. //$image->blurImage(5,5,imagick::CHANNEL_GREEN);
  10. echo $image;
  11. ?>

chopImage(int $width,int $height,int $x,int $y)

参数说明:删除一定范围的图像区域

就不做参数说明,一看便知.

colorizeImage( mixed $colorize , mixed $opacity )混合填充颜色

$colorize 颜色

$opacit 透明度

例子:

  1. <?php
  2. /*
  3. 胶卷底片效果
  4. */
  5. ini_set('display_errors',1);
  6. header('Content-type: image/jpeg');
  7. $image = new Imagick('1.jpg');
  8. $image->negateImage(false);
  9. $image->colorizeImage('#000',1.0);
  10. echo $image;
  11. ?>

embossImage ( float $radius , float $sigma )

功能:返回一个灰度级3D图像 不太好。

例子:

  1. <?php
  2. ini_set('display_errors',1);
  3. header('Content-type: image/jpeg');
  4. $image = new Imagick('1.jpg');
  5. $image->embossImage(1,1);
  6. echo $image;
  7. ?>

(两张效果图)

flipImage(void)

功能:创建图像倒影(垂直翻转)

例子:

  1. <?php
  2. ini_set('display_errors',1);
  3. header('Content-type: image/jpeg');
  4. $image = new Imagick('1.jpg');
  5. $image->flipImage();
  6. echo $image;
  7. ?>

flopImage(void)

功能:图像水平横向翻转

  1. <?php
  2. ini_set('display_errors',1);
  3. header('Content-type: image/jpeg');
  4. $image = new Imagick('1.jpg');
  5. $image->flopImage();
  6. echo $image;
  7. ?>

frameImage(mixed $matte_color,int $width, int $height,int $inner_bevel, int $outer_bevel)

功能:创建3D图像边框

参数说明:

$matte_color:颜色

$inner_bevel:边框内部倾斜度

$outer_bevel:外部边框倾斜度

例子:

  1. <?php
  2. ini_set('display_errors',1);
  3. header('Content-type: image/jpeg');
  4. $image = new Imagick('1.jpg');
  5. $color=new ImagickPixel();
  6. $color->setColor("rgb(220,220,220)");
  7. $image->frameImage($color,11,11,1,10);
  8. echo $image;
  9. ?>

注意事项:

$width(宽度)不能小于$inner_bevel(边框内部倾斜度)

Imagick::gammaImage (float $gamma [,int $channel= Imagick::CHANNEL_ALL])

功能:调整图像灰度系数

参数说明:

float $gamma:灰度系数值

$channel 默认为 Imagick::CHANNEL_ALL

Imagick::CHANNEL_ALL

例子 1:

  1. <?php
  2. ini_set('display_errors',1);
  3. header('Content-type: image/jpeg');
  4. $image = new Imagick('1.jpg');
  5. $image->gammaImage(30);
  6. echo $image;
  7. ?>

例子 2:

  1. <?php
  2. ini_set('display_errors',1);
  3. header('Content-type: image/jpeg');
  4. $image = new Imagick('1.jpg');
  5. $image->gammaImage(30);
  6. echo $image;
  7. ?>

gaussianBlurImage(float $radius,float $sigma [, int $channel= Imagick::CHANNEL_ALL ])

功能:高斯模糊处理 类似于photo的高斯模糊

参数说明:

float $radius:高斯模糊的半径,像素,不包括中心象素。

float $sigma:高斯的标准偏差,以像素为单位,我觉得这个参数最重要.

int $channel:图像颜色模式.

  1. <?php
  2. ini_set('display_errors',1);
  3. header('Content-type: image/jpeg');
  4. $image = new Imagick('1.jpg');
  5. $image->gaussianBlurImage(30,3);
  6. echo $image;
  7. ?>

levelImage(float $blackPoint,float $gamma,float $whitePoint [,int $channel= Imagick::CHANNEL_ALL ])

功能:调整图像的色阶(Adjusts the levels of an image)

参数说明:

  1. <?php
  2. ini_set('display_errors',1);
  3. header('Content-type: image/jpeg');
  4. $image = new Imagick('1.jpg');
  5. $image->levelImage(4,4,4);
  6. echo $image;
  7. ?>

例子2:

  1. <?php
  2. ini_set('display_errors',1);
  3. header('Content-type: image/jpeg');
  4. $image = new Imagick('1.jpg');
  5. $image->levelImage(200,200,200,imagick::CHANNEL_GREEN);
  6. echo $image;
  7. ?>

magnifyImage(void)

功能说明:简便的图像等比例放大2倍(Is a convenience method that scales an image proportionally to twice its original size. )

例子:

  1. <?php
  2. ini_set('display_errors',1);
  3. header('Content-type: image/jpeg');
  4. $image = new Imagick('1.jpg');
  5. $image->magnifyImage ();
  6. echo $image;
  7. ?>

medianFilterImage(float $radius)

功能:特是的滤镜 有点像photoshop 调色刀滤镜

  1. <?php
  2. ini_set('display_errors',1);
  3. header('Content-type: image/jpeg');
  4. $image = new Imagick('1.jpg');
  5. $color=new ImagickPixel();
  6. $color->setColor("rgb(220,220,220)");
  7. $image->medianFilterImage(5);
  8. echo $image;
  9. ?>

minifyImage(void)

功能:图小缩小一倍(Scales an image proportionally to half its size)

例子:

  1. <?php
  2. ini_set('display_errors',1);
  3. header('Content-type: image/jpeg');
  4. $image = new Imagick('1.jpg');
  5. $image->minifyImage();
  6. echo $image;
  7. ?>

modulateImage(float $brightness,float $saturation,float $hue)

功能:控制调整图像的 亮度、饱和度、色调。

参数说明:

float $brightness: 亮度

float $saturation :饱和度

float $hue 色调

例子1:

  1. <?php
  2. ini_set('display_errors',1);
  3. header('Content-type: image/jpeg');
  4. $image = new Imagick('1.jpg');
  5. $image->modulateImage(100,1,100);
  6. echo $image;
  7. ?>

例子2:

  1. <?php
  2. ini_set('display_errors',1);
  3. header('Content-type: image/jpeg');
  4. $image = new Imagick('1.jpg');
  5. $image->modulateImage(250,1,250);
  6. echo $image;
  7. ?>

motionBlurImagemotionBlurImage(float $radius,float $sigma,float $angle [, int $channel= Imagick::CHANNEL_DEFAULT ])

功能:模拟运动模糊(Simulates motion blur),类似photoshop的动感模糊滤镜功能

参数说明:

float $radius: 高斯 半径,不包过中心像素。

float $sigma:标准偏差的高斯,以像素为单位。【重要参数】

float $angle:模糊角度。

int $channel:图像颜色模式。默认为 Imagick::CHANNEL_DEFAULT

例子1:

  1. <?php
  2. ini_set('display_errors',1);
  3. header('Content-type: image/jpeg');
  4. $image = new Imagick('1.jpg');
  5. $color=new ImagickPixel();
  6. $color->setColor("rgb(220,220,220)");
  7. $image->motionBlurImage (61,10,10);
  8. echo $image;
  9. ?>

例子2:

  1. <?php
  2. ini_set('display_errors',1);
  3. header('Content-type: image/jpeg');
  4. $image = new Imagick('1.jpg');
  5. $color=new ImagickPixel();
  6. $color->setColor("rgb(220,220,220)");
  7. $image->motionBlurImage (201,10,100);
  8. echo $image;
  9. ?>

oilPaintImage ( float $radius ):

功能说明:模拟油画滤镜(Simulates an oil painting)

例子:

  1. <?php
  2. ini_set('display_errors',1);
  3. header('Content-type: image/jpeg');
  4. $image = new Imagick('1.jpg');
  5. $color=new ImagickPixel();
  6. $color->setColor("rgb(220,220,220)");
  7. $image->oilPaintImage(1);
  8. echo $image;
  9. ?>

radialBlurImage(float $angle [,int $channel= Imagick::CHANNEL_ALL ])

功能:径向模糊(Radial blurs an image)

  1. <?php
  2. ini_set('display_errors',1);
  3. header('Content-type: image/jpeg');
  4. $image = new Imagick('1.jpg');
  5. $color=new ImagickPixel();
  6. $color->setColor("rgb(220,220,220)");
  7. $image->radialBlurImage(30);
  8. echo $image;
  9. ?>

raiseImage(int $width,int $height,int $x,int $y,bool $raise)

功能说明:创建3D图像按钮(Creates a simulated 3d button-like effect)

  1. <?php
  2. ini_set('display_errors',1);
  3. header('Content-type: image/jpeg');
  4. $image = new Imagick('1.jpg');
  5. $color=new ImagickPixel();
  6. $color->setColor("rgb(220,220,220)");
  7. $image->raiseImage(10,10,3,5,6);
  8. echo $image;
  9. ?>