germania-kg/imagefinder

1.0.4 2022-03-30 10:08 UTC

This package is auto-updated.

Last update: 2024-03-29 03:44:20 UTC


README

Callable wrapper around Symfony's Finder Component.
For convenience purposes prepared for finding image files.

Packagist PHP version Build Status Scrutinizer Code Quality Code Coverage Build Status

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