我们使用智能剪裁将图片剪裁至200*200px
- use GrafikaGrafika;
- $editor = Grafika::createEditor();
- $editor->open( $image, 'yanying-smaller.jpg' );
- $editor->crop( $image, 200, 200, 'smart' );
- $editor->save( $image, 'yanying-smart.jpg' );
发现还是可以突出重点的

GIF缩略图
压缩GIF,不丢失动画
grafika可以直接压缩GIF图片,并且不丢失动画功能。
- use GrafikaGrafika;
- $editor = Grafika::createEditor();
- $editor->open( $image, 'sample.gif' );
- $editor->resizeFit( $image, 250, 128 );
- $editor->save( $image, 'output.gif' );
我们这里将原图压缩到原来的一半,发现动画并没有丢失

移除GIF动画效果
当然,如果有需要,我们也可以直接移除GIF的动画效果
- use GrafikaGrafika;
- $editor = Grafika::createEditor();
- $editor->open( $image, 'sample.gif' );
- $editor->flatten( $image );
- $editor->save( $image, 'output-no-animation.gif' );

图片合并
图片合并需要2张图片,将其中一张作为基本图,准备的第二章图片就是放置在基础图片之上。
我们首先来看代码
- use GrafikaGrafika;
- $editor = Grafika::createEditor();
- $editor->open($image1 , 'yanying-h.jpg');
- $editor->open($image2 , 'yanying-smaller.jpg');
- $editor->blend ( $image1, $image2 , 'normal', 0.9, 'center');
- $editor->save($image1,'333/yanying-blend.jpg');
解释一下
首先打开两张图片,其中$image1为基础图片,也就是放在下面的。重点在blend这个方法。
其中
- 第一个参数为基础图片
- 第二个参数为放置在基础图片之上的图片normal, multiply, overlay or screen.,这里的类型意思就是图片叠加的模式,下面会给出实例看每种的不同。
- 第三个参数为透明度,这个不说太多,容易想到。
- 第四个为位置,有10个选择,其中,前面9种为用户自定义拜访位置,而最后一个是智能拜访,由grafika来判断摆放在哪里好。top-left, top-center, top-right, center-left, center, center-right, bottom-left, bottom-center, bottom-right and smart
- 第五个参数为可选参数,表示图片2距离图片1左边的距离
- 第六个参数也为可选参数,表示图片2距离图片1上边的距离
我们试着摆几种情况。
1、normal
其中位置信息:center,透明度为0.9,也就是上面代码的那种

2、multiply
位置信息:,top-left,其他不变

3、overlay
位置信息:bottom-right,其他不变

4、screen
位置信息:,最后一个位置参数不给,也就是默认top-left

图像旋转
图像旋转比较简单,只需要给一个旋转角度参数就可以了,如果想要给背景填充个颜色,再给一个颜色参数即可。(默认不给背景色为黑色)
(编辑:PHP编程网 - 黄冈站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|