Created
October 14, 2015 09:54
-
-
Save mx-moth/d2a0dcb2a677f37dcbdb to your computer and use it in GitHub Desktop.
Thoughts on Wagtail image resizing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h2>{{ page.title }}</h2> | |
{# As 'header' is in 'sizes' for BlogPost.feature_image, this rendition will be already present #} | |
{% image page.feature_image header %} | |
{# Can also use any old filter here, does not need to be one of 'sizes', or a nickname #} | |
{% image page.feature_image height-200 %} | |
{{ page.body }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BlogPost(Page): | |
body = RichTextField() | |
# As a Blog.feature_image is used only in a set of known sizes, | |
# on the blog index, and on the blog post page itself. | |
feature_image = ImageField('wagtailimages.Image', sizes=[ | |
'thumnail', 'header', # Can use nicknames here | |
'width-400', # Or just normal filter strings | |
]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Nicknames for common sizes used across the site. Keeps things DRY. | |
# Nicknames could also be used as part of the lazy image resizing, | |
# with the generated URLs being something like `/_images/<IMAGE_PK>/<NICKNAME>/` | |
# and only preset nicknames being used for resizing. | |
# This also stops a potential DDOS attack from someone running: | |
# | |
# for x in $( seq 1000 2000 ) ; do for y in $( seq 1000 2000 ) ; do | |
# curl "http://example.com/_images/1/max-${x}x${y}" & | |
# done ; done | |
WAGTAILIMAGE_FLITER_NICKNAMES = { | |
'header': 'fill-1000x200', | |
'thumbnail': 'max-300x300', | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment