def __init__(self, replay): # if the debug option is selected, minimaps will be printed to a file # and a stringIO containing the minimap image will be saved for # every minite in the game and the minimap with creep highlighted # will be printed out. self.debug = replay.opt.debug # # Initialisations # # The following dict contains creep spread area for each player self.creep_spread_by_minute = dict() # The following dict contains a minimap highlighted with # creep spread for each player if self.debug: self.creep_spread_image_by_minute = dict() # The following dict contains all the active cgus in every time frame self.creep_gen_units = dict() # The following dict corresponds to # creep_gen_units storing the time of each CGU self.creep_gen_units_seconds = dict() # Convert all possible CGU radii into a sets # of coordinates centred around the origin, # in order to use this with the CGUs, the centre point will be # subtracted with coordinates of cgus created in game self.unit_name_to_radius = {"CreepTumor": 10, "Hatchery": 8, "NydusCanal": 5} self.radius_to_coordinates = dict() for x in self.unit_name_to_radius: self.radius_to_coordinates[self.unit_name_to_radius[x]] = self.radius_to_map_positions( self.unit_name_to_radius[x] ) # Get map information replayMap = replay.map self.map_height = 100.0 if self.debug: mapsio = StringIO(replayMap.minimap) im = PIL_open(mapsio) # remove black box around minimap cropped = im.crop(im.getbbox()) cropsizeX = replay.map.map_info.camera_right - replay.map.map_info.camera_left cropsizeY = replay.map.map_info.camera_top - replay.map.map_info.camera_bottom cropsize = (cropsizeX, cropsizeY) # Resize height to map_height, and compute new width that # would preserve aspect ratio self.map_width = int(cropsize[0] * (float(self.map_height) / cropsize[1])) self.mapSize = self.map_height * self.map_width minimapSize = (self.map_width, int(self.map_height)) if self.debug: self.minimap_image = cropped.resize(minimapSize, ANTIALIAS) mapOffsetX = replayMap.map_info.camera_left mapOffsetY = replayMap.map_info.camera_bottom mapCenter = [mapOffsetX + cropsize[0] / 2.0, mapOffsetY + cropsize[1] / 2.0] # this is the center of the minimap image, in pixel coordinates imageCenter = [(self.map_width / 2), self.map_height / 2] # This is the scaling factor to go from the SC2 coordinate # system to pixel coordinates self.image_scale = float(self.map_height) / cropsize[1] self.transX = imageCenter[0] + self.image_scale * (mapCenter[0]) self.transY = imageCenter[1] + self.image_scale * (mapCenter[1])
def main(): from os import listdir, mkdir from os.path import isfile, join, exists from Image import open as Image_open subject = "fireworks" base = "/var/www/html/pg/" begin = base + "gen/begin.html" end = base + "gen/end.html" subject_base = base + subject + "/" img_dir = base + "images/%s/" % subject th_dir = base + "images/th/%s/" % subject new_index = base + subject + ".html" html_images_path = "./images/%s/" % subject html_th_images_path = "./images/th/%s/" % subject size = (102, 76) with open(begin) as f: begin_html = f.read() with open(end) as f: end_html = f.read() # Working with files only. images = [f for f in listdir(img_dir) if isfile(join(img_dir, f))] img_html = "" if not exists(th_dir): mkdir(th_dir) for filename in images: #Generate thumbnail infile = img_dir + filename outfile = th_dir + "th_" + filename im = Image_open(infile) im.thumbnail(size) im.save(outfile, "JPEG") # Generate image html img_html += """ <a href="%s%s" title="%s" data-gallery> <img src="%s%s" width=102 height=76 alt="%s"> </a> """ % (html_images_path, filename, filename, html_th_images_path, filename, filename) f = open(new_index, "w") # Delete previous index.html f.seek(0) f.truncate() f.write(begin_html) f.write(img_html) f.write(end_html) f.close()
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 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