Created
March 11, 2013 18:18
-
-
Save bobmagicii/5136370 to your computer and use it in GitHub Desktop.
ImageFilterIterator extends FilterIterator and uses FilesystemIterator itself
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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