Repository: matthewwithanm/django-imagekit

Issue #41: Converting from .png (in "Palette" mode) to .jpeg doesn't work
Created: 2011-11-01T20:57:36Z
Specifying an explicit format="JPEG" does not work when the input file is in PNG format. Works fine when input is JPEG (haven't tested the usual suspects such as GIF, TIFF yet). Also works fine when format= is NOT specified.
class ZDPlainImage(EncryptedPKModel):

    original = ImageField(max_length=500, upload_to="uploads")

     # ImageKit generated image variations
     thumbnail = ImageSpec([resize.Fit(width=250)], image_field='original', format="JPEG", quality=90)
     display = ImageSpec([resize.Fit(width=650, upscale=False)], image_field='original', format="JPEG", quality=90)

Looks like this used to work well with the old 0.4 version. I updated to the latest django-imagekit today, made the necessary changes (got rid of separate "spec") and found that this doesn't work with the latest version.

Duplicate issue #270: "bad transparency mask" error when upscale=False
Created: 2014-01-22T11:52:37Z
I get a "bad transparency mask" error when converting a GIF to a JPEG, but only when upscale is set to False.  Oddly enough, the error does not occur when upscaling is permitted.
Is there a recommended workaround?
Many thanks.
Here is the model definition:
class PhotoModel(models.Model):
    large = ImageSpecField(source='image_file',
        processors=[Transpose(), ResizeToFit(width=500, height=400, upscale=False)],
        format='JPEG',
        options={'quality':90})

Traceback:
Traceback (most recent call last):
  File "/Users/alexington/.virtualenvs/project/lib/python2.7/site-packages/django/core/handlers/base.py", line 114, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/alexington/.virtualenvs/project/lib/python2.7/site-packages/django/db/transaction.py", line 339, in inner
    return func(*args, **kwargs)
  File "/Users/alexington/.virtualenvs/project/lib/python2.7/site-packages/django/views/generic/base.py", line 69, in view
    return self.dispatch(request, *args, **kwargs)
  File "/Users/alexington/.virtualenvs/project/lib/python2.7/site-packages/django/views/generic/base.py", line 87, in dispatch
    return handler(request, *args, **kwargs)
  File "/Users/alexington/.virtualenvs/project/lib/python2.7/site-packages/django/views/generic/edit.py", line 171, in post
    return self.form_valid(form)
  File "/Users/alexington/sites/project_github/project/core/photos/views.py", line 16, in form_valid
    'previewUrlLarge': photo.large.url,
  File "/Users/alexington/.virtualenvs/project/lib/python2.7/site-packages/imagekit/cachefiles/__init__.py", line 84, in url
    return self._storage_attr('url')
  File "/Users/alexington/.virtualenvs/project/lib/python2.7/site-packages/imagekit/cachefiles/__init__.py", line 74, in _storage_attr
    existence_required.send(sender=self, file=self)
  File "/Users/alexington/.virtualenvs/project/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 185, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/Users/alexington/.virtualenvs/project/lib/python2.7/site-packages/imagekit/registry.py", line 53, in existence_required_receiver
    self._receive(file, 'on_existence_required')
  File "/Users/alexington/.virtualenvs/project/lib/python2.7/site-packages/imagekit/registry.py", line 61, in _receive
    call_strategy_method(file, callback)
  File "/Users/alexington/.virtualenvs/project/lib/python2.7/site-packages/imagekit/utils.py", line 140, in call_strategy_method
    fn(file)
  File "/Users/alexington/.virtualenvs/project/lib/python2.7/site-packages/imagekit/cachefiles/strategies.py", line 15, in on_existence_required
    file.generate()
  File "/Users/alexington/.virtualenvs/project/lib/python2.7/site-packages/imagekit/cachefiles/__init__.py", line 93, in generate
    self.cachefile_backend.generate(self, force)
  File "/Users/alexington/.virtualenvs/project/lib/python2.7/site-packages/imagekit/cachefiles/backends.py", line 108, in generate
    self.generate_now(file, force=force)
  File "/Users/alexington/.virtualenvs/project/lib/python2.7/site-packages/imagekit/cachefiles/backends.py", line 96, in generate_now
    file._generate()
  File "/Users/alexington/.virtualenvs/project/lib/python2.7/site-packages/imagekit/cachefiles/__init__.py", line 97, in _generate
    content = generate(self.generator)
  File "/Users/alexington/.virtualenvs/project/lib/python2.7/site-packages/imagekit/utils.py", line 123, in generate
    content = generator.generate()
  File "/Users/alexington/.virtualenvs/project/lib/python2.7/site-packages/imagekit/specs/__init__.py", line 158, in generate
    options=self.options)
  File "/Users/alexington/.virtualenvs/project/lib/python2.7/site-packages/pilkit/utils.py", line 350, in process_image
    return img_to_fobj(img, format, autoconvert, **options)
  File "/Users/alexington/.virtualenvs/project/lib/python2.7/site-packages/pilkit/utils.py", line 17, in img_to_fobj
    return save_image(img, StringIO(), format, options, autoconvert)
  File "/Users/alexington/.virtualenvs/project/lib/python2.7/site-packages/pilkit/utils.py", line 177, in save_image
    img, save_kwargs = prepare_image(img, format)
  File "/Users/alexington/.virtualenvs/project/lib/python2.7/site-packages/pilkit/utils.py", line 332, in prepare_image
    img = MakeOpaque().process(img).convert('RGB')
  File "/Users/alexington/.virtualenvs/project/lib/python2.7/site-packages/pilkit/processors/base.py", line 223, in process
    new_img.paste(img, img)
  File "/Users/alexington/.virtualenvs/project/lib/python2.7/site-packages/PIL/Image.py", line 1118, in paste
    self.im.paste(im, box, mask.im)
ValueError: bad transparency mask

Closing comment (2014-08-04T21:38:47Z): I believe this is related to #41. I tried finding the latest version of the commit referenced in the issue, but couldn't locate it in master.