def test_processor_registry(self):
        self.assertEqual(thumbnail.get_processor('resize'), ResizeProcessor)
        self.assertEqual(thumbnail.get_processor('crop'), CropToFitProcessor)
        self.assertEqual(thumbnail.get_default_processor(), ResizeProcessor)
        self.assertEqual(thumbnail.get_processor('bad'), ResizeProcessor)

        thumbnail.register_processor('whatever', ResizeProcessor)
        self.assertEqual(thumbnail.get_processor('whatever'), ResizeProcessor)

        thumbnail.register_processor('crop', CropToFitProcessor, default=True)
        self.assertEqual(thumbnail.get_default_processor(), CropToFitProcessor)
        self.assertEqual(thumbnail.get_processor('bad'), CropToFitProcessor)
Пример #2
0
    def __init__(self, source_image, width, height, dest=None, proc=None, *args,
                 **kwargs):
        self.source_image = source_image
        self.width = width
        self.height = height
        self.processor = get_processor(proc)(*args, **kwargs)

        is_remote = False
        if dest is None:
            is_remote, dest = build_thumbnail_name(source_image, width, height, self.processor)

        self.is_remote = is_remote
        self.dest = dest

        # Is a remote image download the image and make available
        if self.is_remote:
            source_image = self.get_remote_image(self.source_image, self.dest)
            self.source_image = source_image
            self.is_remote, self.dest = build_thumbnail_name(source_image, width, height, self.processor)

        self.cache_dir = getattr(settings, 'CUDDLYBUDDLY_THUMBNAIL_CACHE', None)

        for var in ('width', 'height'):
            try:
                setattr(self, var, int(getattr(self, var)))
            except ValueError:
                raise ThumbnailException('Value supplied for \'%s\' is not an int' % var)
        if self.processor is None:
            raise ThumbnailException('There is no image processor available')

        self.generate()