def LoadImages( self, key ): """ load new inmages into class storage """ self.images = [] print "help_dict: ", self.help_dict # get images from hardcoded array for image in self.help_dict[ key ]: # open PIL image print "image: ", path.join( HELP_DIR, image ) image1 = PILopen( path.join( HELP_DIR, image ) ) # resize to fit canvas area image1 = image1.resize( ( self.size_x , self.size_y ), ANTIALIAS ) # make into a tkimage im = PhotoImage( image1 ) # add to list of images to display self.images.append( im )
class Image(): # {{{ def __init__(self, fqpn, options): # {{{ try: self.image = Iopen(fqpn) except IOError: raise (self.filePath, self.fileName) = split(fqpn) self.format = self.image.format self.mode = self.image.mode self.size = self.image.size self.options = options # }}} def __unicode__(self): return self.fileName def save(self, fqpn = None, type = None): # {{{ if fqpn is not None: if type == 'MS': self.image.save(fqpn) elif type == 'T': self.image.save(fqpn) else: self.image.save(fqpn) else: if type == 'MS': self.image.save(self.filePath + '/MS_' + self.fileName) elif type == 'T': self.image.save(self.filePath + '/T_' + self.fileName) else: self.image.save(self.filePath + '/' + self.fileName) # }}} def resize(self): # {{{ '''Method resizes the picture to the maximum allowed size if size in horisontal plane is bigger than maximum defined in config file. We do this because Gallery has limits in terms of estetics the horisontal way, but not in the vertical way. ''' if int(self.size[0]) > int(self.options['maxsize']): # diffValue will make sure the aspect ratio is kept for the resize # We force result to be an int since we only want "whole" numbers. diffValue = self.size[0] / float(self.options['maxsize']) sizeHor = int(self.size[0] / diffValue) sizeVer = int(self.size[1] / diffValue) self.image = self.image.resize((sizeHor,sizeVer), ANTIALIAS) self.size = self.image.size return self.image return self.image # }}} def thumbnail(self): # {{{ self.image.thumbnail( ( int(self.options['thumbnailx']), int(self.options['thumbnaily']) ), ANTIALIAS ) self.size = self.image.size return self.image # }}} def rotate(self, angle): # {{{ self.image = self.image.rotate(int(angle)) self.size = self.image.size return self.image