roelvanduijnhoven / reverse-image-cover
0.3.1
2019-05-06 06:44 UTC
Requires
- php: >=5.4
Requires (Dev)
- phpunit/phpunit: 4.*
This package is auto-updated.
Last update: 2022-02-01 12:50:10 UTC
README
一个小型库,可以计算当图像作为元素背景投影时显示的源图像部分。
例如,可以使用它通过预处理图像以仅返回裁剪部分来减少带宽。最终结果将与查看器相同。
目前仅支持使用百分比定位图像并覆盖图像的背景。
用法
$viewport = new BackgroundCoverViewport( $viewportWidth, $viewportHeigt, $backgroundPositionX, $backgroundPositionY ); $crop = $viewport->computeUsedCrop( $imageWidth, $imageHeight ); echo "Visible part of image starts at({$crop[0]}, {$crop[1]}) "; echo "and has a dimension of {$crop[2]} x {$crop[3]}";
测试
可以通过以下方式运行测试
composer install
vendor/bin/phpunit
测试套件可以可视化如下
- 运行服务器
php -S localhost:8080
- 访问 http://localhost:8080/tests/demo.php`