jouwweb/reverse-image-cover

此包已弃用且不再维护。未建议替代包。

计算当源图像被视口覆盖时可见的部分

0.3.1 2019-05-06 06:44 UTC

This package is auto-updated.

Last update: 2022-02-01 13:34:26 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]}";

测试

可以通过以下方式运行测试

  1. composer install
  2. vendor/bin/phpunit

测试套件可以按以下方式可视化

  1. 运行服务器 php -S localhost:8080
  2. 访问http://localhost:8080/tests/demo.php`