degal/thumbnail.py
changeset 122 292aaba6d6ec
parent 116 2d3721b9ffd0
child 123 31c4a328ef96
equal deleted inserted replaced
121:3bed35e79f41 122:292aaba6d6ec
    61         elif img_height > thumb_height :
    61         elif img_height > thumb_height :
    62             width = max(img_width * thumb_height / img_height, 1)
    62             width = max(img_width * thumb_height / img_height, 1)
    63             height = thumb_height
    63             height = thumb_height
    64         
    64         
    65         return width, height 
    65         return width, height 
       
    66     
       
    67     def resize (self, img) :
       
    68         """
       
    69             Resize the give image as needed.
       
    70         """
       
    71 
       
    72         return img.resize(self.size, resample=PIL.Image.ANTIALIAS)
       
    73     
       
    74     def auto_orient (self, img, orient_info) :
       
    75         """
       
    76             Automatically orient the image using the given orientation info.
       
    77         """
       
    78         
       
    79         # unpack
       
    80         mirroring, rotation = orient_info
       
    81 
       
    82         if mirroring :
       
    83             # XXX
       
    84             pass
       
    85 
       
    86         if rotation :
       
    87             # since these are in steps of 90 degrees, it should keep the right size
       
    88             # but gah, PIL wants these as counter-clockwise!
       
    89             img = img.rotate(360 - rotation)
       
    90         
       
    91         # ok
       
    92         return img
    66 
    93 
    67     def update (self) :
    94     def update (self) :
    68         """
    95         """
    69             Render new output thumbnail.
    96             Render new output thumbnail.
    70         """
    97         """
    71 
    98 
       
    99         # start with origional image
       
   100         img = self.image.img
       
   101 
    72         # create resized copy of main image, using our size
   102         # create resized copy of main image, using our size
    73         thumb = self.image.img.resize(self.size, resample=PIL.Image.ANTIALIAS)
   103         img = self.resize(img)
       
   104 
       
   105         # got orientation info?
       
   106         if self.image.orientation :
       
   107             img = self.auto_orient(img, self.image.orientation)
    74 
   108 
    75         # write it out
   109         # write it out
    76         thumb.save(self.path)
   110         img.save(self.path)
    77         
   111