def process_image(path): basename = os.path.basename(path).split('.')[0] dirname = os.path.dirname(path) frame_directory = os.path.join(dirname, basename) mosaic_path = prepend_to_path(path, 'Mosaic_of') mosaic_frames = prepend_to_path(frame_directory, 'Mosaic_of') gif_name = mosaic_frames + '.gif' total_frames = MessageProcessor.DEFAULT_GIF_FRAMES path_pairs = [(path, mosaic_path)] return mosaic_path, gif_name, frame_directory, mosaic_frames, total_frames, path_pairs
def process_gif(path): splitter = GifSplitter(path) splitter.save_frames() original_frames = splitter.out_path mosaic_frames = prepend_to_path(original_frames, 'Mosaic_of') if not os.path.exists(mosaic_frames): os.mkdir(mosaic_frames) total_frames = len(os.listdir(original_frames)) gif_name = prepend_to_path(path, 'Mosaic_of') mosaic_path = gif_name path_pairs = [] for fp in sorted_ls(original_frames): new_fp = os.path.join(mosaic_frames, os.path.basename(fp)) path_pairs.append((fp, new_fp)) return mosaic_path, gif_name, original_frames, mosaic_frames, total_frames, path_pairs
def cleanup(username=None, mosaic_file=None, frame_directory=None, output_file=None, is_animated=True, frame_duration=0.1, mode='I'): if username is None: return if is_animated: mosaic_frames = prepend_to_path(frame_directory, 'Mosaic_of') stitcher = GifStitcher(mosaic_frames, output_file) stitcher.make_gif(frame_duration, mode) print('cleaning up directories with') for directory in [mosaic_frames, frame_directory]: if os.path.exists(directory): shutil.rmtree(directory) print(output_file) UserAccessor().create_gallery_item(username, mosaic_file) print('done')
def __init__(self, frame_directory, out_file=None): self.frame_directory = frame_directory self.out_file = out_file if out_file is not None else prepend_to_path( frame_directory + '.gif', 'new_gif') self.resize_frames()
def set_output_file(self): return prepend_to_path(self.original_file, 'Mosaic_of')
def set_frame_directory(self): basename = self.original_file.split('.')[0] return prepend_to_path(basename, 'Mosaic_of')