germania-kg / imagefinder
1.0.4
2022-03-30 10:08 UTC
Requires
- php: ^5.6|^7.0
- symfony/finder: ^3.1
Requires (Dev)
- php-coveralls/php-coveralls: ^2.0
- phpunit/phpunit: ^5.7|^6.0|^7.0
This package is auto-updated.
Last update: 2024-11-29 05:26:35 UTC
README
Callable wrapper around Symfony's Finder Component.
For convenience purposes prepared for finding image files.
Installation
$ composer require germania-kg/imagefinder
Usage
Each iterator item will be an instance of Symfony's SplFileInfo extension.
use Germania\ImageFinder\ImageFinder; use Symfony\Component\Finder\Finder; // Setup $finder = new Finder; $image_finder = new ImageFinder( $finder ); // Grab from directory $images = $image_finder( '/path/to/photos' ); foreach ($images as $image) { // Stolen from Symfony docs: // Dump the absolute path var_dump($file->getRealPath()); // Dump the relative path to the file, omitting the filename var_dump($file->getRelativePath()); // Dump the relative path to the file var_dump($file->getRelativePathname()); }
Customization
The constructor accepts an array with allowed file extensions.
$allowed = array("jpe?g", "webp" ); $image_finder = new ImageFinder( $finder, $allowed );
To configure allowed extensions during runtime, set member variable extensions:
$image_finder = new ImageFinder( $finder); $image_finder->extensions = array("jpe?g", "webp" );
Development
$ git clone https://github.com/GermaniaKG/ImageFinder.git
$ cd ImageFinder
$ composer install
Unit tests
Either copy phpunit.xml.dist
to phpunit.xml
and adapt to your needs, or leave as is. Run PhpUnit test or composer scripts like this:
$ composer test # or $ vendor/bin/phpunit