I am using Django and easy-thumbnails 2.3. My intention is to take an image, scale it down so that it fits a square and fill the empty area with white color in case of non-square original images. Also in case of transparent images the transparency shall be changed to white.
My settings.py contains the following lines:
THUMBNAIL_PROCESSORS = (
'easy_thumbnails.processors.colorspace',
'easy_thumbnails.processors.autocrop',
'easy_thumbnails.processors.scale_and_crop',
'easy_thumbnails.processors.filters',
'easy_thumbnails.processors.background',
)
THUMBNAIL_ALIASES = {
'':{
'square_image': {'background':'#fff','replace_alpha':'#fff','size':(200,200)},
},
}
THUMBNAIL_TRANSPARENCY_EXTENSION = 'jpg'
I've tried some debugging and everything seems to work quite well and makes sense until the code reaches a line 318 in the background-processor function of easy-thumbnails processors.py
:
im = colorspace(im, replace_alpha=background, **kwargs)
Here the debugger returns straight to the method that was calling background(im, size, background=None, **kwargs)
.
Is there anything wrong with my configuration of square_image
in THUMBNAIL_ALIASES? Could it be anything else?
It turns out that you can't use 'background':'#fff'
from the background processor and 'replace_alpha':'#fff'
from the colorspace processor at the same time, as the background
-key is turned into replace_alpha
in
im = colorspace(im, replace_alpha=background, **kwargs)
and then you end up with two replace_alpha
, as one is still in **kwargs
. This causes the error. But it also turns out that in
THUMBNAIL_ALIASES = {
'':{
'square_image': {'background':'#fff','replace_alpha':'#fff','size':(200,200)}, #wrong
},
}
you don't even need replace_alpha
. The background processor does not add bars at the sides of a non-fitting image, but instead the image gets written on a - in my case white - background. The colorspace conversion does not seem to happen before that. So the proper definition would be
THUMBNAIL_ALIASES = {
'':{
'square_image': {'background':'#fff','size':(200,200)},
},
}