def __getattr__(self, name):
    match = re.match(GET_THUMB_PATTERN, name)
    if match is None:
        raise AttributeError, name
    width, height, method = match.groups()
    size = int(width), int(height)

    def get_photo_thumbnail_filename():
        file, ext = path.splitext(self.get_photo_filename())
        return file + '_%sx%s' % size + ext

    def get_photo_thumbnail_url():
        url, ext = path.splitext(self.get_photo_url())
        return url + '_%sx%s' % size + ext

    thumbnail = get_photo_thumbnail_filename()

    if not path.exists(thumbnail):
        img = Image.open(self.get_photo_filename())
        img.thumbnail(size, Image.ANTIALIAS)
        img.save(thumbnail)

    if method == "url":
        return get_photo_thumbnail_url
    else:
        return get_photo_thumbnail_filename