4)、我们再用一张完全不同的图片测试
- use GrafikaGrafika;
- $editor = Grafika::createEditor();
- $result = $editor->compare('yanying.jpg' , 'yanying-h.jpg');
- var_dump($result); // int 39
结果39,越来越大,越来越不像
2、比较图片是否相同
grafika提供方法equal来检查两张图片是否完全相同。这里的检查是一个像素一个像素的检测,所以时间可能会较长。
当然grafika也会预检查,如果两张图片大小不相同,则直接返回false。只有其他都相同后才会进行逐像素检查。
我们这里对比之前创建的一张缩略图,因为大小不一致,所以直接返回false
- use GrafikaGrafika;
- $editor = Grafika::createEditor();
- $result = $editor->equal('yanying.jpg' , 'yanying-smaller.jpg');
- var_dump($result); // boolean false
智能剪裁
智能剪裁是自动识别图像中的重要部分,剪裁时候偏向于保留重点部分。
不过grafika也提供了人为操控位置剪裁,我们先说这个。
基本位置剪裁
基本位置剪裁包含9个位置
- top-left
- top-center
- top-right
- center-left
- center
- center-right
- bottom-left
- bottom-center
- bottom-right
我们这里一起说了,这里我们使用900*600的图片,分成9块
- use GrafikaGrafika;
- $editor = Grafika::createEditor();
-
- $src = 'yanying.jpg';
- $editor->open( $image, $src );
- $editor->crop( $image, 300, 200, 'top-left' );
- $editor->save( $image, 'result1.jpg' );
- $editor->free( $image );
-
- $editor->open( $image, $src );
- $editor->crop( $image, 300, 200, 'top-center' );
- $editor->save( $image, 'result2.jpg' );
- $editor->free( $image );
-
- $editor->open( $image, $src );
- $editor->crop( $image, 300, 200, 'top-right' );
- $editor->save( $image, 'result3.jpg' );
- $editor->free( $image );
-
- $editor->open( $image, $src );
- $editor->crop( $image, 300, 200, 'center-left' );
- $editor->save( $image, 'result4.jpg' );
- $editor->free( $image );
-
- $editor->open( $image, $src );
- $editor->crop( $image, 300, 200, 'center' );
- $editor->save( $image, 'result5.jpg' );
- $editor->free( $image );
-
- $editor->open( $image, $src );
- $editor->crop( $image, 300, 200, 'center-right' );
- $editor->save( $image, 'result6.jpg' );
- $editor->free( $image );
-
- $editor->open( $image, $src );
- $editor->crop( $image, 300, 200, 'bottom-left' );
- $editor->save( $image, 'result7.jpg' );
- $editor->free( $image );
-
- $editor->open( $image, $src );
- $editor->crop( $image, 300, 200, 'bottom-center' );
- $editor->save( $image, 'result8.jpg' );
- $editor->free( $image );
-
- $editor->open( $image, $src );
- $editor->crop( $image, 300, 200, 'bottom-right' );
- $editor->save( $image, 'result9.jpg' );
- $editor->free( $image );
看下结果

智能剪裁
原图
 (编辑:PHP编程网 - 黄冈站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|