Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: bad transparency mask with FrameAware wrapper #648

Open
mihalikv opened this issue Oct 9, 2024 · 1 comment
Open

ValueError: bad transparency mask with FrameAware wrapper #648

mihalikv opened this issue Oct 9, 2024 · 1 comment

Comments

@mihalikv
Copy link

mihalikv commented Oct 9, 2024

With latest version of easy-thumbnails 2.10 there is introduced support for gif processing.
I tried functionality with GIF attached in this issue, this gif have first frame with im.mode == 'P'. There is code here to convert every frame to 'RGBA' with help of FrameAware wraper, hover it is not working.
Currentlly I am not sure why, but here is test case how it should work and second test case with FrameAware where it is not working.

from PIL import Image
from easy_thumbnails.processors import FrameAware

def test_original_pil(im):
    num_frames = im.n_frames
    for i in range(num_frames):
        im.seek(i)
        print(im.mode)
        converted_image = im.convert('RGBA')
        base = Image.new('RGBA', converted_image.size, '#fff')
        base.paste(converted_image, mask=converted_image)

def test_with_frame_aware(im):
    num_frames = im.n_frames
    for i in range(num_frames):
        im.seek(i)
        im = FrameAware(im).convert('RGBA')
        base = Image.new('RGBA', im.size, '#fff')
        # this will fail with ValueError: bad transparency mask
        # on first frame with mode == 'P'
        base.paste(im, mask=im)

test_image = '/home/vilo/dog-smile.gif'
image_test_1 = Image.open(test_image)
test_original_pil(image_test_1)
image_test_2 = Image.open(test_image)
test_with_frame_aware(image_test_2)

dog-smile

@dkoenigroer
Copy link

Does this issue produce errors like this?

KeyError: 'P'
  File "PIL/JpegImagePlugin.py", line 639, in _save
    rawmode = RAWMODE[im.mode]
OSError: cannot write mode P as JPEG
  File "django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "django/core/handlers/base.py", line 220, in _get_response
    response = response.render()
  File "django/template/response.py", line 114, in render
    self.content = self.rendered_content
  File "django/template/response.py", line 92, in rendered_content
    return template.render(context, self._request)
  File "django/template/backends/django.py", line 61, in render
    return self.template.render(context)
  File "django/template/base.py", line 171, in render
    return self._render(context)
  File "django/template/base.py", line 163, in _render
    return self.nodelist.render(context)
  File "django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 1000, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 961, in render_annotated
    return self.render(context)
  File "django/template/loader_tags.py", line 159, in render
    return compiled_parent._render(context)
  File "django/template/base.py", line 163, in _render
    return self.nodelist.render(context)
  File "django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 1000, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 961, in render_annotated
    return self.render(context)
  File "django/template/loader_tags.py", line 159, in render
    return compiled_parent._render(context)
  File "django/template/base.py", line 163, in _render
    return self.nodelist.render(context)
  File "django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 1000, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 961, in render_annotated
    return self.render(context)
  File "django/template/loader_tags.py", line 159, in render
    return compiled_parent._render(context)
  File "django/template/base.py", line 163, in _render
    return self.nodelist.render(context)
  File "django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 1000, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 961, in render_annotated
    return self.render(context)
  File "django/template/loader_tags.py", line 159, in render
    return compiled_parent._render(context)
  File "django/template/base.py", line 163, in _render
    return self.nodelist.render(context)
  File "django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 1000, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 961, in render_annotated
    return self.render(context)
  File "django/template/loader_tags.py", line 159, in render
    return compiled_parent._render(context)
  File "django/template/base.py", line 163, in _render
    return self.nodelist.render(context)
  File "django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 1000, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 961, in render_annotated
    return self.render(context)
  File "django/template/loader_tags.py", line 159, in render
    return compiled_parent._render(context)
  File "django/template/base.py", line 163, in _render
    return self.nodelist.render(context)
  File "django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 1000, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 961, in render_annotated
    return self.render(context)
  File "django/template/loader_tags.py", line 65, in render
    result = block.nodelist.render(context)
  File "django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 1000, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 961, in render_annotated
    return self.render(context)
  File "django/template/loader_tags.py", line 65, in render
    result = block.nodelist.render(context)
  File "django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 1000, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 961, in render_annotated
    return self.render(context)
  File "django/template/defaulttags.py", line 242, in render
    nodelist.append(node.render_annotated(context))
  File "django/template/base.py", line 961, in render_annotated
    return self.render(context)
  File "django/template/loader_tags.py", line 210, in render
    return template.render(context)
  File "django/template/base.py", line 173, in render
    return self._render(context)
  File "django/template/base.py", line 163, in _render
    return self.nodelist.render(context)
  File "django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 1000, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 961, in render_annotated
    return self.render(context)
  File "django/template/defaulttags.py", line 242, in render
    nodelist.append(node.render_annotated(context))
  File "django/template/base.py", line 961, in render_annotated
    return self.render(context)
  File "django/template/defaulttags.py", line 242, in render
    nodelist.append(node.render_annotated(context))
  File "django/template/base.py", line 961, in render_annotated
    return self.render(context)
  File "django/template/defaulttags.py", line 326, in render
    return nodelist.render(context)
  File "django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 1000, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 961, in render_annotated
    return self.render(context)
  File "django/template/defaulttags.py", line 326, in render
    return nodelist.render(context)
  File "django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 1000, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 961, in render_annotated
    return self.render(context)
  File "django/template/base.py", line 1065, in render
    return render_value_in_context(output, context)
  File "django/template/base.py", line 1042, in render_value_in_context
    value = str(value)
  File "django/forms/utils.py", line 79, in __str__
    return self.as_widget()
  File "django/forms/boundfield.py", line 108, in as_widget
    return widget.render(
  File "django/forms/widgets.py", line 278, in render
    context = self.get_context(name, value, attrs)
  File "django/contrib/admin/widgets.py", line 327, in get_context
    "rendered_widget": self.widget.render(name, value, attrs),
  File "filer/fields/file.py", line 70, in render
    html = render_to_string('admin/filer/widgets/admin_file.html', context)
  File "django/template/loader.py", line 62, in render_to_string
    return template.render(context, request)
  File "django/template/backends/django.py", line 61, in render
    return self.template.render(context)
  File "django/template/base.py", line 171, in render
    return self._render(context)
  File "django/template/base.py", line 163, in _render
    return self.nodelist.render(context)
  File "django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 1000, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 961, in render_annotated
    return self.render(context)
  File "django/template/defaulttags.py", line 422, in render
    return strip_spaces_between_tags(self.nodelist.render(context).strip())
  File "django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 1000, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 961, in render_annotated
    return self.render(context)
  File "django/template/defaulttags.py", line 326, in render
    return nodelist.render(context)
  File "django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 1000, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 961, in render_annotated
    return self.render(context)
  File "django/template/defaulttags.py", line 326, in render
    return nodelist.render(context)
  File "django/template/base.py", line 1000, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 1000, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
  File "django/template/base.py", line 961, in render_annotated
    return self.render(context)
  File "django/template/library.py", line 258, in render
    _dict = self.func(*resolved_args, **resolved_kwargs)
  File "filer/templatetags/filer_admin_tags.py", line 212, in file_icon
    return file_icon_context(file, detail is True, width, height)
  File "filer/templatetags/filer_admin_tags.py", line 157, in file_icon_context
    icon_url = thumbnailer.get_thumbnail(thumbnail_options).url
  File "easy_thumbnails/files.py", line 513, in get_thumbnail
    thumbnail = self.generate_thumbnail(
  File "easy_thumbnails/files.py", line 401, in generate_thumbnail
    img = engine.save_pil_image(
  File "easy_thumbnails/engine.py", line 77, in save_pil_image
    image.save(destination, format=format, **options)
  File "PIL/Image.py", line 2568, in save
    save_handler(self, fp, filename)
  File "PIL/JpegImagePlugin.py", line 642, in _save
    raise OSError(msg) from e

We recently updated Django, Django-CMS, Filter etc. and got this in 2.10. We can go back to 2.0 but we would stuck on Django 5.0.x then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants