def _test_thumbnails_deletion(self, thumbnails_full_paths):
        thumbnailer = get_thumbnailer()

        for image in self.images:
            thumbnailer.delete_thumbnails(image.original)

        self._test_thumbnails_not_exist(thumbnails_full_paths)
    def _test_thumbnails_deletion(self, thumbnails_full_paths):
        thumbnailer = get_thumbnailer()

        for image in self.images:
            thumbnailer.delete_thumbnails(image.original)

        self._test_thumbnails_not_exist(thumbnails_full_paths)
Exemple #3
0
 def delete_image_files(sender, instance, **kwargs):
     """
     Deletes the original image and created thumbnails.
     """
     image_fields = (models.ImageField,)
     thumbnailer = get_thumbnailer()
     for field in instance._meta.fields:
         if isinstance(field, image_fields):
             # Make Django return ImageFieldFile instead of ImageField
             field_file = getattr(instance, field.name)
             thumbnailer.delete_thumbnails(field_file)
Exemple #4
0
    def create_thumbnails(self):
        thumbnailer = get_thumbnailer()
        thumbnails_full_paths = []

        for image in self.images:
            thumbnail = thumbnailer.generate_thumbnail(image.original, **self.thumbnail_options)
            thumbnails_full_paths.append(get_thumbnail_full_path(thumbnail.url))

        # Check thumbnails exist in the file system.
        for path in thumbnails_full_paths:
            assert os.path.isfile(path)  # `isfile` returns `True` if path is an existing regular file.

        return thumbnails_full_paths
Exemple #5
0
    def create_thumbnails(self):
        thumbnailer = get_thumbnailer()
        thumbnails_full_paths = []

        for image in self.images:
            thumbnail = thumbnailer.generate_thumbnail(image.original, **self.thumbnail_options)
            thumbnails_full_paths.append(get_thumbnail_full_path(thumbnail.url))

        # Check thumbnails exist in the file system.
        for path in thumbnails_full_paths:
            assert os.path.isfile(path)  # `isfile` returns `True` if path is an existing regular file.

        return thumbnails_full_paths
Exemple #6
0
 def __init__(self,
              source_field,
              image_type=None,
              image_processor=None,
              do_upscale=False,
              settings=settings,
              **options):
     self.source_field = source_field
     self.image_type = image_type
     self.image_processor = image_processor or get_thumbnailer(
     ).generate_thumbnail
     self.do_upscale = do_upscale
     self.settings = settings or get_settings()
     self.options = options
     return
    def _render(self, context):
        source = self.source_var.resolve(context)
        options = self.get_thumbnail_options(context)
        for key, expr in self.options:
            value = self.no_resolve.get(str(expr), expr.resolve(context))
            options[key] = value

        thumbnailer = get_thumbnailer()
        thumbnail = thumbnailer.generate_thumbnail(source, **options)

        if self.context_name is None:
            return escape(thumbnail.url)
        else:
            context[self.context_name] = thumbnail
            return ''
    def render(self, context):
        source = self.source_var.resolve(context)
        options = {'size': self.size_var.resolve(context)}
        for key, expr in self.options:
            value = self.no_resolve.get(text_type(expr), expr.resolve(context))
            options[key] = value

        thumbnailer = get_thumbnailer()
        thumbnail = thumbnailer.generate_thumbnail(source, **options)

        if self.context_name is None:
            return escape(thumbnail.url)
        else:
            context[self.context_name] = thumbnail
            return ''
Exemple #9
0
def get_srcset_image(source,
                     width,
                     image_type=None,
                     image_processor=None,
                     do_upscale=False,
                     settings=settings,
                     **options):
    """Build and return the source set image objects."""

    # have to wrap sizes so they pass to thumbnailer as 'widthxheight'.
    # this is probably the worst part of the thumbnailers API.
    calc_img_dim = lambda source, width: f"{width}x{int((width / source.width) * source.height)}"

    # prevent upscaling by default.  Filter sizes out that are greater than the
    # uploaded source image.
    if not do_upscale and width >= source.width:
        return

    # give the options of passing in a custom image processor.
    image_processor = image_processor or get_thumbnailer().generate_thumbnail

    return image_processor(
        source, **dict({'size': calc_img_dim(source, width)}, **options))