Skip to content
Advertisement

InvalidImageFormatError Exception The source file does not appear to be an image

So I am using fallback default image to avoid 500 error and it is not successful. I keep getting the same error “InvalidImageFormatError: The source file does not appear to be an image”.

In my case I try to thumbnail an image that does not exist. But it is assumed that if the image does not exist it should use the one that is in default as fallback. Any ideas? Someone who has happened in the same way and found a solution? In my case this is my code {% oscar_thumbnail child_image.original|default:'image/default.png' "450x450" format="WEBP" padding=True as thumb_child %}

I am migrating from sorl-thumbnails which comes by default with django_oscar for easy_thumbnails. The tag OSCAR_THUMBNAIL is used by django_oscar and oscar replaces it with the thumbnailer that is in settings in this case easy_thumbnails. I have debugged the code, and it is entering the easy_thumb classes well … and the parameters are arriving correctly. The thing is, it doesn’t make me fallback when the image it’s trying to process doesn’t exist. I have a database with products that have associated images, many of these do not exist in my local environment, because in production they are in s3, and I do not have my settings configured for s3 in my development environment. But hey, the question is that it should fallback when there is no image, or there is a reference to an image that does not physically exist. With which I intend to do fallback if it exists but it keeps giving me error 500 and it does not show me the page, I get the django page with the exceptions. Oh and I’ve also tried the native easy_thumb tag …

Any ideas? Thanks in advance!

enter image description here

Advertisement

Answer

The problem was the following, for the default filter to take the value the previous expression must be evaluated to False, for this reason it explodes, because there is no image, the thumbnailer cannot create the object, the solution is to make another filter to check if the image exists in the storage, and return a boolean value.

{%% oscar_thumbnail child_image.original|image_exist|default:'image/default.png' "450x450" format="WEBP" padding=True as thumb_child %%}

Thanks.

Advertisement