Germania KG · ImageFinder
Callable wrapper around Symfony's Finder Component.
For convenience purposes prepared for finding image files., (*1)
, (*2)
Installation
$ composer require germania-kg/imagefinder
Usage
Each iterator item will be an instance of Symfony's SplFileInfo extension., (*3)
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., (*4)
$allowed = array("jpe?g", "webp" );
$image_finder = new ImageFinder( $finder, $allowed );
To configure allowed extensions during runtime, set member variable extensions:, (*5)
$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:, (*6)
$ composer test
# or
$ vendor/bin/phpunit