当前位置: 首页 > 科技观察

PHP图像处理库Grafika详细教程(二):图像特效处理模块

时间:2023-03-12 10:01:38 科技观察

这篇文章是上一篇的续篇《PHP图片处理库Grafika详细教程(1):图像基本处理》,因为grafika的功能太多,所以单独写,其他点这里《1、图像基本处理》?《3、图像属性处理》《4、图形绘制》开门见山,直接进入示例,了解更多图片过滤和滤镜点击上面的链接。Grafika提供了11种过滤器功能,可以满足开发中任何情况的需要。这里先介绍一个操作方法:apply:可以对图片应用滤镜效果。使用模糊参数模糊图片。模糊度范围为0-100。值越大,图片越模糊useGrafika\Grafika;$editor=Grafika::createEditor();$editor->open($image,'yanying-smaller.jpg');$filter=Grafika::createFilter('Blur',50);//模糊度为10,模糊值为0-100$editor->apply($image,$filter);//对图像应用滤镜$editor->save($image,'yanying-blur.jpg');我们将图片的模糊参数调整为50图片的亮度调整使用亮度,使图片变亮或变暗,其中亮度值范围为-100到-1,变暗0图片不变1-100图片变量useGrafika\Grafika;$editor=Grafika::createEditor();$editor->open($image,'yanying-smaller.jpg');$filter=Grafika::createFilter('亮度',-50);$editor->apply($image,$filter);$editor->save($image,'333/yanying-Brightness-1.jpg');改变图片的颜色使用Colorize参数调整图片的红、绿、蓝三种基本颜色来改变图片的颜色。颜色参数(红、绿、蓝取值范围相同)范围从-100到-1,颜色递减;如果为0,则不变;如果值为1-100,表示颜色值增加useGrafika\Grafika;$editor=Grafika::createEditor();$editor->open($image,'yanying-smaller.jpg');$filter=Grafika::createFilter('着色',-50,50,-50);$editor->apply($image,$filter);$editor->save($image,'333/yanying-Colorize.jpg');改变图像的对比度使用对比度参数改变图像的对比度。对比度值和前面的差不多,-100到-1,对比度降低;0不变;1到100,对比度增加。对比是什么?我自己也不是太清楚。毕竟不是设计useGrafika\Grafika;$editor=Grafika::createEditor();$editor->open($image,'yanying-smaller.jpg');$filter=Grafika::createFilter('Contrast',50);$editor->apply($image,$filter);$editor->save($image,'333/yanying-Contrast.jpg');图像噪声使用Dither对图像进行噪声处理,其参数值只有两个diffusion:diffusion;有序:常规使用Grafika\Grafika;$editor=Grafika::createEditor();$editor->open($image,'yanying-smaller.jpg');$filter=Grafika::createFilter('Dither','diffusion');$editor->apply($image,$filter);$editor->save($image,'333/yanying-Dither-diffusion.jpg');图像电平调整Gamma参数平时不常用,可以理解仅在专业图像领域使用的是色标,它是灰度亮度值与灰度等级之间的数学关系。这里的Gamma功能是对图像的色阶进行校正,让图像看起来更正确。这里的数字取值范围只有最小值,没有***值,只要>=1.0,就可以用Grafika\Grafika;$editor=Grafika::createEditor();$editor->open($image,'yanying-smaller.jpg');$filter=Grafika::createFilter('Gamma',2.0);$editor->apply($image,$filter);$editor->save($image,'333/yanying-Gamma.jpg');使用Grayscale丢弃图像的所有颜色,只保留黑色和白色,没有值。useGrafika\Grafika;$editor=Grafika::createEditor();$editor->open($image,'yanying-smaller.jpg');$filter=Grafika::createFilter('Grayscale');$editor->apply($图像,$过滤器);$editor->save($image,'333/yanying-Grayscale.jpg');图像反转过程图像反转,即使其始终如胶片。使用Invert参数实现图像反转效果,没有可选值useGrafika\Grafika;$editor=Grafika::createEditor();$editor->open($image,'yanying-smaller.jpg');$filter=Grafika::createFilter('Invert');$editor->apply($image,$filter);$editor->save($image,'333/yanying-Invert.jpg');图片的像素化和光栅化就是将矢量图形转化为由像素组成的点阵图形,也叫光栅化。搞ps的应该都知道,这个参数是有取值范围的,只要大于等于1,取值越大,像素越大。useGrafika\Grafika;$editor=Grafika::createEditor();$editor->open($image,'yanying-smaller.jpg');$filter=Grafika::createFilter('Pixelate',10);$editor->应用($image,$filter);$editor->save($image,'333/yanying-Pixelate-10.jpg');我们取值5和值10进行比较图片锐化图片锐化是补偿图像的轮廓,增强图像的边缘和灰阶跳跃的部分,使图像变得清晰。可以使用参数Sharpen处理锐化,其值为1-100(含)。useGrafika\Grafika;$editor=Grafika::createEditor();$editor->open($image,'yanying-smaller.jpg');$filter=Grafika::createFilter('锐化',50);$editor->应用($image,$filter);$editor->save($image,'333/yanying-Sharpen.jpg');取50的值看看效果图像的边缘通过数学计算来检测,在ps中比较常用。这里使用Sobel参数实现同样的效果,无值可选useGrafika\Grafika;$editor=Grafika::createEditor();$editor->open($image,'yanying-smaller.jpg');$filter=Grafika::createFilter('Sobel');$editor->apply($image,$filter);$editor->save($image,'333/yanying-Sobel.jpg');