我在django中使用簡易縮略圖庫創建縮略圖。但是,我無法弄清楚如何覆蓋縮略圖命名過程。目前,lib將縮略圖大小附加到文件名中,但我想指定一個自定義名稱,例如_大。這怎麼能做到呢?在django中指定具有簡易縮略圖的文件名後綴
1
A
回答
1
django-easy-thumbnails
使用default renaming function。你可以寫你自己的命名功能,並設置它設置爲默認命名函數庫應該使用,因爲這裏THUMBNAIL_NAMER描述:
myapp.utils
def namer(thumbnailer, prepared_options, source_filename,
thumbnail_extension, **kwargs):
# do something and return name
pass
settings.py
THUMBNAIL_NAMER = 'myapp.utils.namer'
0
您可以定義自己的thumbnail-processor
並把這裏作爲最後一行:http://easy-thumbnails.readthedocs.org/en/latest/ref/settings/#easy_thumbnails.conf.Settings.THUMBNAIL_PROCESSORS
THUMBNAIL_PROCESSORS = (
'easy_thumbnails.processors.colorspace',
'easy_thumbnails.processors.autocrop',
'easy_thumbnails.processors.scale_and_crop',
'easy_thumbnails.processors.filters',
'easy_thumbnails.processors.background',
'yourProject.thumbnail_processors.renaming', #<---- your custom one
)
和處理器文件(yourProject/thumbnail_processors.py
)看起來像:
def renaming(image, bang=False, **kwargs):
"""
rename the filename here and just return the image
"""
return image
沒有測試
雖然
+0
感謝您的回答,但我不太清楚如何「重命名文件名」。該圖像是一個PIL對象,沒有名爲filename的屬性。 – RunLoop
相關問題
- 1. 刪除使用簡易縮略圖生成的所有縮略圖Django App
- 2. Django縮略圖,簡單
- 3. 帶簡易縮略圖的Django Rest框架
- 4. PIL /簡易縮略圖丟失依賴關係Django
- 5. 生成縮略圖與易縮略圖
- 6. 的Git忽略所有的精縮爲後綴的文件
- 7. 如何在Chirpy中指定min文件名後綴?
- 8. 在sorl的get_thumbnail函數中指定文件名和目標縮略圖
- 9. 在簡易縮略圖中使用jpegoptim與PIL
- 10. Django縮略圖
- 11. 如何忽略具有給定前綴的文件?
- 12. 具有新後綴的Renamea文件
- 13. 如何過濾帶有特定前綴和後綴(擴展名)的文件名?
- 14. SORL-縮略圖和文件重命名
- 15. 蟒蛇pyinotify中監視指定後綴的文件在目錄
- 16. Django的易縮略圖:複製ThumbnailerImagefield對象
- 17. 如何列出具有特定前綴名稱的mat文件?
- 18. 在Python中查找具有數字後綴的文件
- 19. 使用通配符排除具有特定後綴的文件
- 20. 使用Django +易縮略圖/上彈性魔豆
- 21. 更改簡碼中的WooCommerce縮略圖
- 22. Django忽略交易
- 23. 在PHP SDK中的AWS Elastic Transcoder中指定縮略圖的尺寸和生成的縮略圖的數量
- 24. 如何在這篇文章中縮略圖縮略圖?
- 25. 蝙蝠前綴帶有文件夾字符和後綴日期的文件名
- 26. YouTube v3中的縮略圖縮略圖
- 27. 獲取具有指定擴展名的所有文件node.js
- 28. 引導盤中的縮略圖指標
- 29. JSON是否具有+ json後綴約定?
- 30. Laravel - 如何顯示具有公用文件夾中指定名稱的圖像?
我已經添加了一個關於在縮略圖文件名生成中使用別名的問題:https://github.com/SmileyChris/easy-thumbnails/issues/375 –