I'm developing a website with:
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:
By default, Wagtail will only crop enough to change the aspect ratio of the image to match the ratio in the resize-rule.
In some cases (e.g. thumbnails), it may be preferable to crop closer to the focal point, so that the subject of the image is more prominent.
You can do this by appending -c at the end of the resize-rule. For example, if you would like the image to be cropped as closely as possible to its focal point, add -c100:
{% image page.photo fill-200x200-c100 %}
This will crop the image as much as it can, without cropping into the focal point.
If you find that -c100 is too close, you can try -c75 or -c50. Any whole number from 0 to
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.