def centerText(target, working_file_name, extra=False): text = [] line_colors = [] text.append(git_info.getBaseRepoName(target)) line_colors.append(info_color) text.append(git_info.getLastCommitDate(target)) line_colors.append(info_color) if SHOW_COMMIT_INFO: lines = git_info.getLastCommit(target).split('\n') for line in lines: while len(line) > 0: text.append(line[:MAX_MSG_LENGTH]) line = line[MAX_MSG_LENGTH:] line_colors.append(info_color) if extra: text.append("File count: " + git_info.getFileCount(target)) line_colors.append(info_color) for author in sorted(authors): text.append(author + ' ' + str(author_lines[author])) author_color = authors[author] % len(colors) line_colors.append(colors[author_color]) overlaid = image_tools.overlayLines( working_file_name, text, line_colors, OVERRIDE_FONT, OVERRIDE_X, OVERRIDE_Y, 2) return overlaid
def cornerText(target, working_file_name): text = [] line_colors = [] line_colors.append(greenish) text.append(git_info.getBaseRepoName(target)) for author in sorted( authors): text.append(author + ' ' + str(author_lines[author])) author_color = authors[author] % len(colors) line_colors.append(colors[author_color]) x = 100 y = ROW_OFFSET overlaid = image_tools.overlayLines(working_file_name, text, line_colors, 40, x, y) return overlaid
def centerText(target, working_file_name, extra = False): text = [] line_colors = [] text.append(git_info.getBaseRepoName(target)) line_colors.append(white) text.append(git_info.getLastCommitDate(target)) line_colors.append(white) if extra: text.append("File count: " + git_info.getFileCount(target)) line_colors.append(white) for author in sorted( authors): text.append(author + ' ' + str(author_lines[author])) author_color = authors[author] % len(colors) line_colors.append(colors[author_color]) overlaid = image_tools.overlayLines(working_file_name, text, line_colors, OVERRIDE_FONT, OVERRIDE_X, OVERRIDE_Y,2) return overlaid
def createImage(target, first=True, index=0, movie=False, info=True, forced_width=0, forced_height=0): '''Generates a digital image based on the contents of the target folder.''' # Figure out the filenames based on the target name. base = git_info.getBaseRepoName(target) output_file_name = os.path.join( OUTPUT_FOLDER, base + '_%04d' % index + '.png') # Generate the list of paths to the target files that will be used # to generate the images. allFiles, neededFiles = getAllFiles([target], first) # Calculate the scale of the output based on the total number of files. global scale_div if first: scale_div = 1 - len(allFiles)/1000.0 if scale_div < .1: scale_div = .1 if NO_SCALE: scale_div = 1 print(('Scale = ' + str(scale_div))) # Generate the list of images that will be created. allFileImages = [] for _, f in enumerate(allFiles): dirname, filename = os.path.split(f) fileImage = os.path.join(TEMP_FOLDER, dirname.split( os.path.sep)[-1] + '_' + filename + '.png') allFileImages.append(fileImage) # Setup a temp folder for the files during processing. disk.makeFolder(TEMP_FOLDER) # Setup an output folder for the end result. disk.makeFolder(OUTPUT_FOLDER) # Generate the images themselves. drawImages(output_file_name, neededFiles, scale_div) # Get just the images we need, # ignoring other temp images that are generated. folderImages = os.listdir(TEMP_FOLDER) runImages = [] for image in folderImages: for match in allFileImages: if os.path.split(match)[1] in image: runImages.append(os.path.join(TEMP_FOLDER, image)) runImages.sort() if len(runImages) == 0: print("Error: No images found.") return None # Append all the files together into a long strip. pile_file = image_tools.pile(runImages) # Split the strip into each segments. separated_files = image_tools.separate(pile_file) disk.cleanUp(pile_file) # Stitch together the segments. connected = image_tools.connect(separated_files) disk.cleanUp(separated_files) # Force the height and width to be even numbers. if FORCE_EVEN: connected = image_tools.make_even(connected) # When making a movie adjust each frame to # the same height and width. if movie and FORCE_WIDTH and not first: img = Image.open(connected) if img.size[0] < forced_width: blank = drawBlank('blank.png', forced_width - img.size[0], img.size[1]) connected = image_tools.couple([connected, blank]) disk.cleanUp('blank.png') img = Image.open(connected) if img.size[1] < forced_height: blank = drawBlank( 'blank.png', img.size[0], forced_height-img.size[1]) connected = image_tools.pile([connected, blank]) disk.cleanUp('blank.png') img.close() del img # Fix the color and brightness. enhanced = image_tools.enhance([connected]) disk.cleanUp(connected) # Apply text overlay in the corner. if CORNER_TEXT: overlaid = cornerText(target, enhanced[0]) disk.cleanUp(enhanced) else: overlaid = enhanced[0] # Apply text overlay in the center. if info: overlaid2 = centerText(target, overlaid, extra=True) disk.cleanUp(overlaid) else: overlaid2 = overlaid disk.move(overlaid2, output_file_name) return output_file_name
msg = '\n ~~(OvO)~~ \n' msg += '\nCreating a bird\'s eye view...\n' msg += 'Folder = {target}\n'.format(target=target) msg += 'Movie = {movie}\n'.format(movie=str(movie)) if movie: msg += 'Revs = {revs}\n'.format(revs=str(revs)) msg += 'Info = {info}\n'.format(info=str(info)) msg += '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n' msg += ' ><> \n' print(msg) if not SAVE_TEMP: disk.deleteFolder(TEMP_FOLDER) if movie: branch = '' try: branch = gitHistory(target, revs, info) base = git_info.getBaseRepoName(target) make_movie.combine(OUTPUT_FOLDER, base) if OPEN_AFTER: disk.open(os.path.join(OUTPUT_FOLDER, 'out.mp4')) finally: response = git_info.resetHead(target, branch) print(response) else: output_file_name = createImage(target=target, info=info) if OPEN_AFTER: disk.open(output_file_name)
def createImage(target, first=True, index=0, movie=False, info=True, alphabetical_sort=False, forced_width=0, forced_height=0): global scale_div base = git_info.getBaseRepoName(target) commit = git_info.getCommitNumber(target) output_file_name = OUTPUT_FOLDER + base + '_%04d' % index + '.png' allFiles, neededFiles = getAllFiles([target], first) if first: scale_div = 1 - len(allFiles) / 1000.0 if scale_div < .1: scale_div = .1 print(('Scale = ' + str(scale_div))) allFileImages = [] for i, f in enumerate(allFiles): dirname, filename = os.path.split(f) fileImage = os.path.join( TEMP_FOLDER, dirname.split(os.path.sep)[-1] + '_' + filename + '.png') allFileImages.append(fileImage) disk.makeFolder(TEMP_FOLDER) disk.makeFolder(OUTPUT_FOLDER) newFileImages = drawImages(output_file_name, neededFiles, scale_div) #newFileImages = limitHeight(newFileImages) # @TODO: Need modify allFiles to include filename changes from chopping files. folderImages = os.listdir(TEMP_FOLDER) runImages = [] for image in folderImages: for match in allFileImages: if os.path.split(match)[1] in image: runImages.append(os.path.join(TEMP_FOLDER, image)) runImages.sort() if alphabetical_sort: total_height = 0 batch = [] separated_files = [] letters = 'abcdefghijklmnopqrstuvwxyz' index = 0 for i, f in enumerate(runImages): img = Image.open(f) name = os.path.split(f)[1] letter = name[0].lower() print((letters[index])) if letter not in letters or letter != letters[index]: while letter != letters[index] and index < 25: index += 1 if TOTAL_HEIGHT - total_height > 0: batch.append( drawBlank('blank.png', MAX_WIDTH, TOTAL_HEIGHT - total_height)) pile_file = image_tools.pile(batch) batch = [] batch.append(f) separated_files.append(pile_file) total_height = img.size[1] else: batch.append(f) total_height += img.size[1] if len(batch) > 0: if TOTAL_HEIGHT - total_height > 0: batch.append( drawBlank('blank.png', MAX_WIDTH, TOTAL_HEIGHT - total_height)) pile_file = image_tools.pile(batch) batch = [] separated_files.append(pile_file) else: pile_file = image_tools.pile(allFileImages) separated_files = image_tools.separate(pile_file) disk.cleanUp(pile_file) connected = image_tools.connect(separated_files) disk.cleanUp(separated_files) if FORCE_EVEN: connected = image_tools.make_even(connected) if movie and FORCE_WIDTH and not first: img = Image.open(connected) if img.size[0] < forced_width: blank = drawBlank('blank.png', forced_width - img.size[0], img.size[1]) connected = image_tools.couple([connected, blank]) disk.cleanUp('blank.png') img = Image.open(connected) if img.size[1] < forced_height: blank = drawBlank('blank.png', img.size[0], forced_height - img.size[1]) connected = image_tools.pile([connected, blank]) disk.cleanUp('blank.png') enhanced = image_tools.enhance([connected]) disk.cleanUp(connected) if CORNER_TEXT: overlaid = cornerText(target, enhanced[0]) disk.cleanUp(enhanced) else: overlaid = enhanced[0] if info: overlaid2 = centerText(target, overlaid, extra=True) disk.cleanUp(overlaid) else: overlaid2 = overlaid # img = Image.open(overlaid2) # if img.size[0] > REALLY_BIG: # image_tools.scale(overlaid2,.5) disk.move(overlaid2, output_file_name) return output_file_name