2015-06-17 35 views

回答

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

我已經添加了一個關於在縮略圖文件名生成中使用別名的問題:https://github.com/SmileyChris/easy-thumbnails/issues/375 –

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

相關問題