ivoba / image-extractor
Image Extractor
v1.0.0
2014-08-28 12:03 UTC
Requires
- php: >=5.4
- symfony/dom-crawler: ~2.5
Requires (Dev)
- ivoba/stop: ~0.2
- phpunit/phpunit: ~3.7
This package is auto-updated.
Last update: 2024-12-10 22:24:06 UTC
README
Extensible Image Extractor to find all Image tags in a string. The library uses the symfony DomCrawler as base of extraction.
- You can add multiple Extractors to find img tags or video tags to f.e resolve youtube thumbs. (or try the Video Preview Image Extractor)
- You can add own XPath expressions to ImageXPathExtractor.
- You can define custom & additional Extractors.
- You can add multiple Filter to filter the found Images.
- You can define custom Filter.
- You can resolve relative image pathes with a FixRelativePathFilter.
As extractor a ImageXPathExtractor gets shipped, which fetches all img tags.
These filters are provided:
- a StrPosFilter which filters images that contain one of the given filter strings.
- a FixRelativePathFilter that adds a basePath to all relative image paths.
Install
Via Composer
{ "require": { "ivoba/image-extractor": "dev-master" } }
Usage
$extractorList = [new ImageXPathExtractor()]; $filter = [new StrPosFilter(['flattr-badge', 'feedburner.com']]; $imageExtractor = new ImageExtractor($extractorList, $filter); $images = $imageExtractor->extract(file_get_contents($file));
A factory method for the default ImageExtractor with a default ImageXPathExtractor is provided:
$imageCreator = ImageExtractor::create();
Testing
$ phpunit
Contributing
Please see CONTRIBUTING for details.
Credits
- Ivo Bathke(https://github.com/ivoba)
License
The MIT License (MIT). Please see License File for more information.