degal/thumbnail.py
author Tero Marttila <terom@fixme.fi>
Wed, 01 Jul 2009 20:15:08 +0300
changeset 139 d3167c40e7b9
parent 125 74f135774567
permissions -rw-r--r--
remove old scripts/cgi-bin stuff. They wouldn't work as such with the new version, and replacements can be written while referring to the history
85
7da934333469 move thumbnail rendering from render.py to thumbnail.py, and implement staleness checking for Images, plus index_images for Folder
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     1
"""
7da934333469 move thumbnail rendering from render.py to thumbnail.py, and implement staleness checking for Images, plus index_images for Folder
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     2
    State for thumbnails; derivates of Images
7da934333469 move thumbnail rendering from render.py to thumbnail.py, and implement staleness checking for Images, plus index_images for Folder
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     3
"""
7da934333469 move thumbnail rendering from render.py to thumbnail.py, and implement staleness checking for Images, plus index_images for Folder
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     4
125
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
     5
import filesystem, exif
85
7da934333469 move thumbnail rendering from render.py to thumbnail.py, and implement staleness checking for Images, plus index_images for Folder
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     6
7da934333469 move thumbnail rendering from render.py to thumbnail.py, and implement staleness checking for Images, plus index_images for Folder
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     7
import PIL.Image
7da934333469 move thumbnail rendering from render.py to thumbnail.py, and implement staleness checking for Images, plus index_images for Folder
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     8
7da934333469 move thumbnail rendering from render.py to thumbnail.py, and implement staleness checking for Images, plus index_images for Folder
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     9
class Thumbnail (filesystem.File) :
7da934333469 move thumbnail rendering from render.py to thumbnail.py, and implement staleness checking for Images, plus index_images for Folder
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    10
    """
7da934333469 move thumbnail rendering from render.py to thumbnail.py, and implement staleness checking for Images, plus index_images for Folder
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    11
        A Thumbnail is a derivate of an Image, usually resized to some other size.
7da934333469 move thumbnail rendering from render.py to thumbnail.py, and implement staleness checking for Images, plus index_images for Folder
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    12
    """
7da934333469 move thumbnail rendering from render.py to thumbnail.py, and implement staleness checking for Images, plus index_images for Folder
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    13
115
d5aa320697df rename Image.pil_image -> Image.img, and shave off ~30ms per image by using Image.resize instead of Image.copy/Image.thumbnail
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
    14
    def __init__ (self, image, subdir, target_size) :
85
7da934333469 move thumbnail rendering from render.py to thumbnail.py, and implement staleness checking for Images, plus index_images for Folder
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    15
        """
7da934333469 move thumbnail rendering from render.py to thumbnail.py, and implement staleness checking for Images, plus index_images for Folder
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    16
            Initialize to link against the given `image`.
7da934333469 move thumbnail rendering from render.py to thumbnail.py, and implement staleness checking for Images, plus index_images for Folder
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    17
            
7da934333469 move thumbnail rendering from render.py to thumbnail.py, and implement staleness checking for Images, plus index_images for Folder
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    18
            `subdir` specifies the directory to store this thumbnail in.
115
d5aa320697df rename Image.pil_image -> Image.img, and shave off ~30ms per image by using Image.resize instead of Image.copy/Image.thumbnail
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
    19
            `target_size` determines the target resolution of the output thumbnail.
85
7da934333469 move thumbnail rendering from render.py to thumbnail.py, and implement staleness checking for Images, plus index_images for Folder
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    20
        """
7da934333469 move thumbnail rendering from render.py to thumbnail.py, and implement staleness checking for Images, plus index_images for Folder
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    21
95
3b00bd676fc9 fix Thumbnail.stale/File.older_than behaviour
Tero Marttila <terom@fixme.fi>
parents: 85
diff changeset
    22
        # our file path, image name inside of the given subdir
3b00bd676fc9 fix Thumbnail.stale/File.older_than behaviour
Tero Marttila <terom@fixme.fi>
parents: 85
diff changeset
    23
        super(Thumbnail, self).__init__(subdir, image.fsname)
85
7da934333469 move thumbnail rendering from render.py to thumbnail.py, and implement staleness checking for Images, plus index_images for Folder
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    24
7da934333469 move thumbnail rendering from render.py to thumbnail.py, and implement staleness checking for Images, plus index_images for Folder
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    25
        # store
7da934333469 move thumbnail rendering from render.py to thumbnail.py, and implement staleness checking for Images, plus index_images for Folder
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    26
        self.image = image
115
d5aa320697df rename Image.pil_image -> Image.img, and shave off ~30ms per image by using Image.resize instead of Image.copy/Image.thumbnail
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
    27
        self.target_size = target_size
85
7da934333469 move thumbnail rendering from render.py to thumbnail.py, and implement staleness checking for Images, plus index_images for Folder
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    28
7da934333469 move thumbnail rendering from render.py to thumbnail.py, and implement staleness checking for Images, plus index_images for Folder
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    29
    def stale (self) :
7da934333469 move thumbnail rendering from render.py to thumbnail.py, and implement staleness checking for Images, plus index_images for Folder
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    30
        """
7da934333469 move thumbnail rendering from render.py to thumbnail.py, and implement staleness checking for Images, plus index_images for Folder
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    31
            Tests if this thumbnail is stale
7da934333469 move thumbnail rendering from render.py to thumbnail.py, and implement staleness checking for Images, plus index_images for Folder
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    32
        """
7da934333469 move thumbnail rendering from render.py to thumbnail.py, and implement staleness checking for Images, plus index_images for Folder
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    33
        
95
3b00bd676fc9 fix Thumbnail.stale/File.older_than behaviour
Tero Marttila <terom@fixme.fi>
parents: 85
diff changeset
    34
        if self.image.older_than(self) :
3b00bd676fc9 fix Thumbnail.stale/File.older_than behaviour
Tero Marttila <terom@fixme.fi>
parents: 85
diff changeset
    35
            # both exist and this is newer
3b00bd676fc9 fix Thumbnail.stale/File.older_than behaviour
Tero Marttila <terom@fixme.fi>
parents: 85
diff changeset
    36
            return False
3b00bd676fc9 fix Thumbnail.stale/File.older_than behaviour
Tero Marttila <terom@fixme.fi>
parents: 85
diff changeset
    37
        
3b00bd676fc9 fix Thumbnail.stale/File.older_than behaviour
Tero Marttila <terom@fixme.fi>
parents: 85
diff changeset
    38
        else :
3b00bd676fc9 fix Thumbnail.stale/File.older_than behaviour
Tero Marttila <terom@fixme.fi>
parents: 85
diff changeset
    39
            # this thumb doesn't exist or is older
3b00bd676fc9 fix Thumbnail.stale/File.older_than behaviour
Tero Marttila <terom@fixme.fi>
parents: 85
diff changeset
    40
            return True
115
d5aa320697df rename Image.pil_image -> Image.img, and shave off ~30ms per image by using Image.resize instead of Image.copy/Image.thumbnail
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
    41
    
125
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
    42
    def calcsize (self, size) :
115
d5aa320697df rename Image.pil_image -> Image.img, and shave off ~30ms per image by using Image.resize instead of Image.copy/Image.thumbnail
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
    43
        """
125
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
    44
            Compute the *real* size of this thumbnail, from the give actual size and our target size.
115
d5aa320697df rename Image.pil_image -> Image.img, and shave off ~30ms per image by using Image.resize instead of Image.copy/Image.thumbnail
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
    45
d5aa320697df rename Image.pil_image -> Image.img, and shave off ~30ms per image by using Image.resize instead of Image.copy/Image.thumbnail
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
    46
            Preserves the aspect ratio etc.
d5aa320697df rename Image.pil_image -> Image.img, and shave off ~30ms per image by using Image.resize instead of Image.copy/Image.thumbnail
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
    47
        """
d5aa320697df rename Image.pil_image -> Image.img, and shave off ~30ms per image by using Image.resize instead of Image.copy/Image.thumbnail
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
    48
        
125
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
    49
        # initial image size
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
    50
        width, height = size
115
d5aa320697df rename Image.pil_image -> Image.img, and shave off ~30ms per image by using Image.resize instead of Image.copy/Image.thumbnail
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
    51
d5aa320697df rename Image.pil_image -> Image.img, and shave off ~30ms per image by using Image.resize instead of Image.copy/Image.thumbnail
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
    52
        # target size
d5aa320697df rename Image.pil_image -> Image.img, and shave off ~30ms per image by using Image.resize instead of Image.copy/Image.thumbnail
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
    53
        thumb_width, thumb_height = self.target_size
d5aa320697df rename Image.pil_image -> Image.img, and shave off ~30ms per image by using Image.resize instead of Image.copy/Image.thumbnail
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
    54
d5aa320697df rename Image.pil_image -> Image.img, and shave off ~30ms per image by using Image.resize instead of Image.copy/Image.thumbnail
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
    55
        # calc new size, preserving aspect ratio
125
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
    56
        # calculations ripped from PIL.Image.thumbnail :)
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
    57
        if width > thumb_width : 
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
    58
            height = max(height * thumb_width / width, 1)
115
d5aa320697df rename Image.pil_image -> Image.img, and shave off ~30ms per image by using Image.resize instead of Image.copy/Image.thumbnail
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
    59
            width = thumb_width
125
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
    60
 
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
    61
        if height > thumb_height :
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
    62
            width = max(width * thumb_height / height, 1)
115
d5aa320697df rename Image.pil_image -> Image.img, and shave off ~30ms per image by using Image.resize instead of Image.copy/Image.thumbnail
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
    63
            height = thumb_height
d5aa320697df rename Image.pil_image -> Image.img, and shave off ~30ms per image by using Image.resize instead of Image.copy/Image.thumbnail
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
    64
        
d5aa320697df rename Image.pil_image -> Image.img, and shave off ~30ms per image by using Image.resize instead of Image.copy/Image.thumbnail
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
    65
        return width, height 
123
31c4a328ef96 move the uncache-del's from commands.main to Image.cleanup, and call it after rendering each image's thumbs
Tero Marttila <terom@fixme.fi>
parents: 122
diff changeset
    66
   
31c4a328ef96 move the uncache-del's from commands.main to Image.cleanup, and call it after rendering each image's thumbs
Tero Marttila <terom@fixme.fi>
parents: 122
diff changeset
    67
    ## operations
122
292aaba6d6ec auto-orientation, although no mirroring support yet
Tero Marttila <terom@fixme.fi>
parents: 116
diff changeset
    68
    def resize (self, img) :
292aaba6d6ec auto-orientation, although no mirroring support yet
Tero Marttila <terom@fixme.fi>
parents: 116
diff changeset
    69
        """
125
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
    70
            Resize the given image as needed.
122
292aaba6d6ec auto-orientation, although no mirroring support yet
Tero Marttila <terom@fixme.fi>
parents: 116
diff changeset
    71
        """
292aaba6d6ec auto-orientation, although no mirroring support yet
Tero Marttila <terom@fixme.fi>
parents: 116
diff changeset
    72
125
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
    73
        return img.resize(self.calcsize(img.size), resample=PIL.Image.ANTIALIAS)
122
292aaba6d6ec auto-orientation, although no mirroring support yet
Tero Marttila <terom@fixme.fi>
parents: 116
diff changeset
    74
    
125
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
    75
    def transform (self, img, orient_info) :
122
292aaba6d6ec auto-orientation, although no mirroring support yet
Tero Marttila <terom@fixme.fi>
parents: 116
diff changeset
    76
        """
125
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
    77
            Transform this image into the output version, resizing, rotating and mirroring in a single step.
122
292aaba6d6ec auto-orientation, although no mirroring support yet
Tero Marttila <terom@fixme.fi>
parents: 116
diff changeset
    78
        """
292aaba6d6ec auto-orientation, although no mirroring support yet
Tero Marttila <terom@fixme.fi>
parents: 116
diff changeset
    79
        
125
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
    80
        # get sizes
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
    81
        img_width, img_height = img_size = img.size
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
    82
        
122
292aaba6d6ec auto-orientation, although no mirroring support yet
Tero Marttila <terom@fixme.fi>
parents: 116
diff changeset
    83
        # unpack
292aaba6d6ec auto-orientation, although no mirroring support yet
Tero Marttila <terom@fixme.fi>
parents: 116
diff changeset
    84
        mirroring, rotation = orient_info
125
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
    85
 
122
292aaba6d6ec auto-orientation, although no mirroring support yet
Tero Marttila <terom@fixme.fi>
parents: 116
diff changeset
    86
        if mirroring :
125
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
    87
            # XXX: does anyone actually use this? Untested
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
    88
            # interaction with rotate is probably wrong
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
    89
            p0, p1 = {
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
    90
                exif.MIRROR_HORIZONTAL: ((0, img_height), (img_width, 0)),
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
    91
                exif.MIRROR_VERTICAL:   ((img_width, 0), (0, img_height)),
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
    92
            }
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
    93
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
    94
        if rotation in (exif.ROTATE_90, exif.ROTATE_270) :
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
    95
            # flip the dimensions to take rotate into account
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
    96
            img_size = img_height, img_width
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
    97
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
    98
        # calc new size
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
    99
        thumb_size = self.calcsize(img_size)
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
   100
 
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
   101
        if rotation in (exif.ROTATE_90, exif.ROTATE_270) :
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
   102
            # flip the dimensions back before rotate
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
   103
            thumb_size = thumb_size[1], thumb_size[0]
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
   104
       
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
   105
        if mirroring :
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
   106
            # perform the transform, can't use ANTIALIAS here :/
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
   107
            img = img.transform(thumb_size, PIL.Image.EXTENT, p0 + p1, PIL.Image.NEAREST)
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
   108
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
   109
        else :
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
   110
            # resize with ANTIALIAS
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
   111
            img = img.resize(thumb_size, resample=PIL.Image.ANTIALIAS)
122
292aaba6d6ec auto-orientation, although no mirroring support yet
Tero Marttila <terom@fixme.fi>
parents: 116
diff changeset
   112
292aaba6d6ec auto-orientation, although no mirroring support yet
Tero Marttila <terom@fixme.fi>
parents: 116
diff changeset
   113
        if rotation :
125
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
   114
            # transform can't rotate
122
292aaba6d6ec auto-orientation, although no mirroring support yet
Tero Marttila <terom@fixme.fi>
parents: 116
diff changeset
   115
            # since these are in steps of 90 degrees, it should keep the right size
292aaba6d6ec auto-orientation, although no mirroring support yet
Tero Marttila <terom@fixme.fi>
parents: 116
diff changeset
   116
            # but gah, PIL wants these as counter-clockwise!
292aaba6d6ec auto-orientation, although no mirroring support yet
Tero Marttila <terom@fixme.fi>
parents: 116
diff changeset
   117
            img = img.rotate(360 - rotation)
292aaba6d6ec auto-orientation, although no mirroring support yet
Tero Marttila <terom@fixme.fi>
parents: 116
diff changeset
   118
        
292aaba6d6ec auto-orientation, although no mirroring support yet
Tero Marttila <terom@fixme.fi>
parents: 116
diff changeset
   119
        return img
85
7da934333469 move thumbnail rendering from render.py to thumbnail.py, and implement staleness checking for Images, plus index_images for Folder
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   120
7da934333469 move thumbnail rendering from render.py to thumbnail.py, and implement staleness checking for Images, plus index_images for Folder
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   121
    def update (self) :
7da934333469 move thumbnail rendering from render.py to thumbnail.py, and implement staleness checking for Images, plus index_images for Folder
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   122
        """
115
d5aa320697df rename Image.pil_image -> Image.img, and shave off ~30ms per image by using Image.resize instead of Image.copy/Image.thumbnail
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   123
            Render new output thumbnail.
85
7da934333469 move thumbnail rendering from render.py to thumbnail.py, and implement staleness checking for Images, plus index_images for Folder
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   124
        """
7da934333469 move thumbnail rendering from render.py to thumbnail.py, and implement staleness checking for Images, plus index_images for Folder
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   125
122
292aaba6d6ec auto-orientation, although no mirroring support yet
Tero Marttila <terom@fixme.fi>
parents: 116
diff changeset
   126
        # start with origional image
292aaba6d6ec auto-orientation, although no mirroring support yet
Tero Marttila <terom@fixme.fi>
parents: 116
diff changeset
   127
        img = self.image.img
292aaba6d6ec auto-orientation, although no mirroring support yet
Tero Marttila <terom@fixme.fi>
parents: 116
diff changeset
   128
125
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
   129
        if self.image.orientation and (self.image.orientation[0] or self.image.orientation[1]) :
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
   130
            # rotate
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
   131
            img = self.transform(img, self.image.orientation)
122
292aaba6d6ec auto-orientation, although no mirroring support yet
Tero Marttila <terom@fixme.fi>
parents: 116
diff changeset
   132
125
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
   133
        else :
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
   134
            # just create resized copy of main image, using our size
74f135774567 fix rotated size of auto-oriented thumbnails, and throw some code at mirroring - untested
Tero Marttila <terom@fixme.fi>
parents: 123
diff changeset
   135
            img = self.resize(img)
85
7da934333469 move thumbnail rendering from render.py to thumbnail.py, and implement staleness checking for Images, plus index_images for Folder
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   136
115
d5aa320697df rename Image.pil_image -> Image.img, and shave off ~30ms per image by using Image.resize instead of Image.copy/Image.thumbnail
Tero Marttila <terom@fixme.fi>
parents: 95
diff changeset
   137
        # write it out
122
292aaba6d6ec auto-orientation, although no mirroring support yet
Tero Marttila <terom@fixme.fi>
parents: 116
diff changeset
   138
        img.save(self.path)
95
3b00bd676fc9 fix Thumbnail.stale/File.older_than behaviour
Tero Marttila <terom@fixme.fi>
parents: 85
diff changeset
   139