Skip to content

Instantly share code, notes, and snippets.

@bobmagicii
Created March 11, 2013 18:18
Show Gist options
  • Save bobmagicii/5136370 to your computer and use it in GitHub Desktop.
Save bobmagicii/5136370 to your computer and use it in GitHub Desktop.
ImageFilterIterator extends FilterIterator and uses FilesystemIterator itself
<?php
class ImageFilterIterator extends FilterIterator {
// overwriting the constructor to automagically create an inner iterator
// to surf the file system when given a path name.
public function __construct($path) {
parent::__construct(new FilesystemIterator($path));
return;
}
// overwriting the accept method to perform a super simple test to
// determine if the files found were images (types we want at least) or
// not.
public function accept() {
if(preg_match('/^(?:gif|jpe?g|png)$/i',$this->getExtension())) {
return true;
} else {
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment