2013-08-19 65 views

回答

0

好吧,我做了這樣的文件photologue/models.py:

IMAGE_EXIF_ORIENTATION_MAP = { 
    6: 0, 
    3: 2, 
    8: 3, 
    1: 4, 
} 


    def pre_cache(self): 
     if self.EXIF.get('Orientation', 1) is not None: 
      im = Image.open(self.image.path) 
      im = im.transpose(IMAGE_EXIF_ORIENTATION_MAP[self.EXIF.get('Orientation', 1)]) 
      im.save(self.image.path) 

     cache = PhotoSizeCache() 
     for photosize in cache.sizes.values(): 
      if photosize.pre_cache: 
       self.create_size(photosize)