def _explode_emote(self, emote, background_image_path, hover): ''' Create a {emote name}_exploded directory This directory contains all frames. The frames are cut out a spritemap if needed. Returns True if animation was not cut out a spritemap. (background image size == individual frames sizes) Returns False if animation was part of a spritemap and cutting was required. (background image size != individual frames sizes) Does not handle hover images. ''' explode_dir = get_explode_directory(self.output_dir, emote, hover) if not os.path.exists(explode_dir): os.makedirs(explode_dir) shutil.copyfile(background_image_path, os.path.join(explode_dir, "background.png")) apngasm('--force', '-D', os.path.join(explode_dir, "background.png"), "-o", explode_dir, '-j', '-x') os.remove(os.path.join(explode_dir, "background.png")) frames_paths = glob(os.path.join(explode_dir, '*.png')) for frame_path in frames_paths: background_image = Image.open(frame_path) if hover: extracted_single_image = extract_single_hover_image(emote, background_image) else: extracted_single_image = extract_single_image(emote, background_image) background_image.close() if cmp(background_image.size, extracted_single_image.size) != 0: extracted_single_image.save(frame_path) else: return True return False
def _reassemble_emote_png(self, emote, hover): ''' Reconstructs a emote from a exploded form to animated .png ''' explode_dir = get_explode_directory(self.output_dir, emote, hover) animation_file = os.path.join(explode_dir, 'animation.xml') with open(animation_file, 'r') as f: animation_xml = etree.parse(f).getroot() if(hover): image_path = get_single_image_path(self.output_dir, emote, True) else: image_path = get_single_image_path(self.output_dir, emote, False) args = [] args = args + ['--force', '-o', image_path] for frame_xml in animation_xml: frame_file = os.path.join(explode_dir, frame_xml.get('src')) delay = self._calculate_frame_delay(frame_xml.get('delay')) args.append(frame_file) args.append(delay) apngasm( *args )
def _reassemble_emote_png(self, emote, hover): ''' Reconstructs a emote from a exploded form to animated .png ''' explode_dir = get_explode_directory(self.output_dir, emote, hover) animation_file = os.path.join(explode_dir, 'animation.xml') with open(animation_file, 'r') as f: animation_xml = etree.parse(f).getroot() if (hover): image_path = get_single_image_path(self.output_dir, emote, True) else: image_path = get_single_image_path(self.output_dir, emote, False) args = [] args = args + ['--force', '-o', image_path] for frame_xml in animation_xml: frame_file = os.path.join(explode_dir, frame_xml.get('src')) delay = self._calculate_frame_delay(frame_xml.get('delay')) args.append(frame_file) args.append(delay) apngasm(*args)
def _explode_emote(self, emote, background_image_path, hover): ''' Create a {emote name}_exploded directory This directory contains all frames. The frames are cut out a spritemap if needed. Returns True if animation was not cut out a spritemap. (background image size == individual frames sizes) Returns False if animation was part of a spritemap and cutting was required. (background image size != individual frames sizes) Does not handle hover images. ''' explode_dir = get_explode_directory(self.output_dir, emote, hover) if not os.path.exists(explode_dir): os.makedirs(explode_dir) shutil.copyfile(background_image_path, os.path.join(explode_dir, "background.png")) apngasm('--force', '-D', os.path.join(explode_dir, "background.png"), "-o", explode_dir, '-j', '-x') os.remove(os.path.join(explode_dir, "background.png")) frames_paths = glob(os.path.join(explode_dir, '*.png')) for frame_path in frames_paths: background_image = Image.open(frame_path) if hover: extracted_single_image = extract_single_hover_image( emote, background_image) else: extracted_single_image = extract_single_image( emote, background_image) background_image.close() if cmp(background_image.size, extracted_single_image.size) != 0: extracted_single_image.save(frame_path) else: return True return False