I'm developing a website with:
- Python
- Django
- Wagtail
In this project there are a lot of images and all of them have an ugly yellow border. In order to remove this border I need to crop all the images sistematically.
Every image has its own focal area (feature supplied by wagtail), a box that exclude the yellow border. However the standard tool for cropping, of wagtail, is useless in this situation and to achieve my goal I've decided to use easy-thumbnails.
Here an example of code in which I use the focal_point of image_object to set all the parameters needed for the cropping operation:
parameters = {
'size': (width, height),
'crop': True,
'detail': False,
'upscale': False,
}
if image_object.has_focal_point():
focal_point = image_object.get_focal_point()
parameters['box'] = "%s,%s,%s,%s" % (
int(focal_point.left),
int(focal_point.top),
int(focal_point.right - focal_point.left),
int(focal_point.bottom - focal_point.top),
)
return get_thumbnailer(image_object.file).get_thumbnail(parameters, generate=True).url
My question is about the "box" parameter. I can't find it on the easy thumbnails docs but I've found examples of use around internet.
Can anyone tell me where I can found any reference about it? Or at least a list of all the parameters allowed with the get_thumbnail method?
Thanks in advance, nifel87
Although I've never tried it for this specific case, the rendition resizing method allows for a parameter to crop closer to the focal point which might help:
The same resize rules can be use with
Image.get_rendition
if you wish to generate the image rendition in Python.Another more involved solution would be to create your own filters (a.k.a. resizing rules), although I'm afraid it isn't documented. Have a look at the implementation of the built-in filters and how to register them. Good luck.