python - Django Imagekit overwrite cachefile_name? -
I am trying to overwrite the module django-imagekit to Here's my code: This does not work at all. Any thoughts? As an example I could have copied closely, it worked fine. Some suggestions are: 1) Make sure you are using avatar_thumb in a scene. The file "bla / blub / test.jpg" will not be generated until then. 2) To ensure that you are "bla / blub / test.jpg", check the configuration of your MEDIA_ROOT is expected to come. Give me an example of something that I was working on. I wanted to give my thumbnail a unique name that can be guessed by the original file name. Imagekit's default scheme has thumbnails names based on hash, which I can not guess. Instead: I want to: Thumbs "directory, which arise from specific fields with a particular model. So I created this ImageSpec subclass and registered it: And then it was used in my model like this: cachefile_name property.
square thumb-150x150 (imageppeak): processor = [resizeToFill (150, 150)] format = 'JPEG' option = {'quality @: 90} @ property def cachefile_name (self): # Simplified for this example "bla / blub / test.jpg" register.generator ('blablub: thumb_150x150', thumb-150x150) class avatar (models.Model): avatar = ProcessedImageField (upload_to = upload_to, processor = [ConvertToRGBA ()], format = 'JPEG', option = {'quality': 60}) avatar_thumb = ImageSpecField (source = 'avatar', id = 'blablub: thumb_150x150') < / Code>
When I view the return value of debug (my cachefile_name ), and the value of cachefile_name, the result is "CACHE / blablub / asdlkfjasd09fsaud0fj.jpg". Where's my fault
Media / 12345.jpg Media / CACHE / 12345 / abcde.jpg
< Overriding IMAGEKIT_SPEC_CACHEFILE_NAMER did not work because I did not want to do all of my cached files "code / media / photos / original / 12345.jpg media / photos / thumb / 12345.jpg
class Thumbnail Sips (Image Speak): Processor = [Thumbnail (200, 200, Anchor. CER , Crop = true, upscale = fail)] format = 'JPEG' option = {'quality': 90} "thumbnail" put in photo / thumb "folder and # name them as source file @property def cachefile_name (self) Only in: source_filename = getattr (self.source, 'name', none) = "photos / thumbs" / source_filename Returns register.generator ('Myapp: Thumbnail, thumbnail edge)
# Provide a unique name Each image file def EF get_file_path (example, filename): ext = filename.split ('.') [- 1] Return "% s.% S"% (uuid.uuid4 (), ext.lower ()) # (, Location = os.path.join (settings.MEDIA_ROOT, 'photos / original') base_url = '/ photos / original') 'photos / original' directory photoStorage = Store the original images in FileSystemStorage class photos (models.Model): Image = Models.ImageField (storage = photoStorage, upload_to = get_file_path) Thumb = ImageSpecField (source = 'image', id = 'MyApp: thumbnail')
Comments
Post a Comment