[英]Get the image (picture) of an django database using django-image-cropping and easy-thumbnails
[英]Django-image-cropping + easy_thumbnails + django-watermarker
有沒有人試圖一起使用所有這些功能? 我只能將它們中的任意兩個組合在一起,但是無法弄清楚如何使用所有三個,我絕對需要它。 我希望從管理員處進行免費裁剪(以選擇要在結果中顯示圖像的哪一部分),將其加水印並使用一些縮略圖別名通過簡單的縮略圖來調整大小/壓縮。
它應該是這樣的: {% cropped_thumbnail Event.photo.pure_events_list.url|watermark:"General watermark" "cropping_free" %}
其中: pure_events_list
是用於輕松縮略圖的縮略圖別名|watermark:"General watermark"
用於獲取圖像的過濾器由url帶水印並返回帶水印圖像的新url
在此先感謝您的幫助!
檢查此模塊easy_thumbnails .. https://pypi.python.org/pypi/django-easy-thumbnails-watermark/0.6.2 PS。如果您是使用Python 3需要適應模塊中的幾行
您必須創建新的templatetag:
from image_cropping.templatetags.cropping import cropped_thumbnail
from watermarker.templatetags.watermark import watermark
@register.simple_tag(takes_context=True)
def cropped_watermarked_thumbnail(context, instance, ratiofieldname, **kwargs):
watermark_params = kwargs.pop('watermark', '')
cropped_image_url = cropped_thumbnail(context, instance, ratiofieldname, **kwargs)
return watermark(cropped_image_url, watermark_params)
並在模板中使用它:
<img src="{% cropped_watermarked_thumbnail product 'crop' scale=1 upscale=True watermark='Watermark,position=C,opacity=100' %}">
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.