def transparent(f, color=util.color("255, 255, 255")): """ 指定パス画像の指定カラー部分透明にする """ if isinstance(f, file): file_path = f.name elif isinstance(f, str): file_path = f img = Image.open(file_path) img = img.convert("RGBA") r = color.r g = color.g b = color.b newData = [] for item in img.getdata(): if item[0] == r and item[1] == g and item[2] == b: newData.append((r, g, b, 0)) else: newData.append(item) img.putdata(newData) tmpdir = tempfile.mkdtemp() f_name = os.path.basename(file_path) output_path = os.path.join(tmpdir, os.path.splitext(f_name)[0]) + ".png" img.save(output_path, "PNG") return output_path
def execute(self, content): regions = [] for image in self.config["image"]: if not os.path.exists(image): logging.error("file not found: {}".format(image)) continue x = self.search_bounding_boxies(image) if self.config.get("color"): for r in x: r.color = util.color(self.config["color"], self.color_table) regions.extend(x) if content.get(self.store): content[self.store].extend(regions) else: content[self.store] = regions for smod in self.sub_modules: sub_res = smod.execute(content) if isinstance(sub_res, dict): content.update(sub_res) elif not isinstance(sub_res, list): content.append(sub_res) else: content.extend(sub_res) return content
def execute(self, content): if not content.get(self.region): raise RegionNotFound(self.region) for r in content[self.region]: r.color = util.color(self.config["color"], self.color_table) return content
def execute(self, content): input_file = self.config["input"] color = util.color(self.config["color"], self.color_table) res = transparent(input_file, color) shutil.copyfile(res, self.config["output"]) shutil.rmtree(os.path.dirname(res)) return content
def __init__(self, config, environ): self.config = config self.environ = environ self.target = config.setdefault("target", "regions") self.outline = config.setdefault("outline", True) self.thickness = config.setdefault("thickness", 3) self.outline_thickness = config.setdefault("outline_thickness", 6) color_table = environ.setdefault("color_table", None) color = config.setdefault("color", None) if color: self.color = util.color(color, color_table) else: self.color = None self.outline_color = util.color( config.setdefault("outline_color", "111, 111, 111"), color_table)