roelvanduijnhoven / reverse-image-cover
Compute visible part of source image when covered in viewport
Installs: 1 191
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 4
Forks: 0
Open Issues: 0
Requires
- php: >=5.4
Requires (Dev)
- phpunit/phpunit: 4.*
This package is auto-updated.
Last update: 2022-02-01 12:50:10 UTC
README
Small library that can compute the part of the source image that is shown when it is being projected onto an element as background.
Can be used for example to reduce bandwidth by preprocessing the image so that only the crop is returned. The end result will be identical to the viewer.
Currently only supports backgrounds that cover the image and use percentages to position the image.
Usage
$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]}";
Tests
Tests can be ran by:
composer install
vendor/bin/phpunit
The test suite can be visualized as follows:
- Run server
php -S localhost:8080
- Visit http://localhost:8080/tests/demo.php`