false positives – wrong files excluded
-
For its simplicity (one line of code!) it works really great, but beware that if a picture with a filename like “MyPicture_300x200.jpeg” is uploaded it will be filtered just like its thumbnails.
I tested it on a customer site where most of his photos already have an indication of the resolution in the name and the “bug” is real.
By now it’s not a complete fault beacause each image on that site has a “-resmushed” version that do get backed up.I’m thinking about a simple workaround but there seems to be none.
The not so simple workaraounds could be:
a) For every media file to be filtered scan the db for a match; IF there’s no match AND the name is in the form of -\d+x\d+\. THEN this must be a thumbnail; a query for each file would be a real performance hit, but a php array with hundreds or even thousands of names could be light to be cached.b) Ask wp for every image dimensions and compile a list of suffixes to identify thumbnails; this could still misfire if an image file has the exact same dimensions as one of the thumbnails in wp.
c) For every media file strip the -\d+x\d+ suffix and chek if there’s a corresponding “master” file; that would be pretty much safe, but maybe not very efficient having to deal with the file system.
I’ll try to submit a patch in the a-style.
PS may I suggest to change the regex from
/-\d+x\d+\.(?:png|jpe?g|bmp|tiff|gif)/
to
/-\d+x\d+\.(?:png|jpe?g|bmp|tiff|gif)$/i
case insensitive and anchored to the end of the stringThank you!
- The topic ‘false positives – wrong files excluded’ is closed to new replies.