1

I'm trying to get started with Django Oscar and I can't get my images to load properly. Once I upload an image, I get this error - 'cannot write mode RGBA as JPEG'. The error comes from line 11:

6 {% block product %}
7       <article class="product_pod">
8           {% block product_image %}
9               <div class="image_container">
10                  {% with image=product.primary_image %}
11                      {% oscar_thumbnail image.original "x155" upscale=False as thumb %} <!-- this line throwing error -->
12                      <a href="{{ product.get_absolute_url }}">
13                          <img src="{{ thumb.url }}" alt="{{ product.get_title }}" class="thumbnail">
14                      </a>
15                  {% endwith %}
16              </div>
17          {% endblock %}

Would this be because I don't have libjpeg properly installed? I'm running this on Windows and it's still not clear to me if I have installed libjpeg correctly. What exactly to I need to do with that package after downloading if that is my issue?

Let me know if I can provide more information that would be helpful.

Jarett
  • 11
  • 1
  • 1
    The issue seems to be that the original image contains an alpha layer, or transparent layer which is not supported by the JPEG format. I'm not sure exactly which Oscar Thumbnail extension you're using, so I don't know where to look to see if the extension supports converting the image to RGB mode beforehand. A possible workaround could be to ensure all applicable images were converted to RGB mode using the code here: https://stackoverflow.com/a/49255449/42346, but if you're constantly getting new images that's probably not a sustainable workaround. – mechanical_meat Mar 11 '21 at 21:13
  • I'm just using the default sorl thumnail. Maybe I'll try a different thumnail extension and see if that gets me anywhere. Any tips or things I could try to get past this? – Jarett Mar 13 '21 at 15:31

2 Answers2

0

I'm not sure if this is the right answer, but changing the django-oscar thumbnail extension to Easy Thumbnails seems to have solved my problem for now. Hopefully this helps others that may encounter the issue. Pypi site for easy thumbnails

Jarett
  • 11
  • 1
0

django-oscar uses sorl-thumbnail to generate thumbnails. The default image format for thumbs is jpeg. But jpeg does not support transparency, so if your source image has a color model that is not compatible with jpeg, you have to either discard the alpha channel (transparency) or create thumbnails with the same filetype as the source image. This can be done by setting THUMBNAIL_PRESERVE_FORMAT = True in settings.py

THUMBNAIL_PRESERVE_FORMAT

Default: False

If True, the format of the input file will be preserved. If False, THUMBNAIL_FORMAT will be used.

https://sorl-thumbnail.readthedocs.io/en/latest/reference/settings.html#thumbnail-preserve-format

Håken Lid
  • 22,318
  • 9
  • 52
  • 67