def dither_atk(img): img = img.convert('L') tmp = atk.atk(img.size[0], img.size[1], img.tostring()) new = Image.fromstring('L', img.size, tmp) return new.convert('RGBA')
def dither(i): """ Take an instance of single-channel PIL.Image, dither and return """ assert i.mode == "L" s = atk.atk(i.size[0], i.size[1], i.tostring()) o = PIL.Image.fromstring("L", i.size, s) return o
def dither(i, *args, **kwargs): """ Take an instance of single-channel PIL.Image, dither and return """ if i.mode != 'L': i = i.convert('L') assert i.mode == 'L' thresh = 100 s = atk.atk(i.size[0], i.size[1], i.tobytes(), 75) o = PIL.Image.frombytes('L', i.size, s) return o
def dither_atk(src_path, dest_path, mime_type): import atk img = Image.open(src_path) img = img.convert('L') sz = img.size tmp = atk.atk(sz[0], sz[1], img.tostring()) new = Image.fromstring('L', sz, tmp) new = img.convert('1') new.save(dest_path, mime_type) return True
def make_dithered(src, dest): if os.path.exists(dest): return True logging.info("make %s" % dest) img = Image.open(src) img = img.convert('L') sz = img.size tmp = atk.atk(sz[0], sz[1], img.tostring()) new = Image.fromstring('L', sz, tmp) new = img.convert('1') new.save(dest) return os.path.exists(dest)