Refactored thumbnail function as a generic filter.