@@ -0,0 +1,1294 @@
+#!/usr/bin/env python%0A# -*- coding: utf-8 -*-%0A%0Aimport click%0Aimport os%0Afrom PIL import Image%0Afrom utils import make_dir_by_file_name%0A%0A%0Adef parse_info_file(info_file, src_w, src_h):%0A    result = %5B%5D%0A    with open(info_file) as f:%0A        for i, line in enumerate(f):%0A            tokens = line.split()%0A            if len(tokens) != 5:%0A                raise RuntimeError('error parse line #' + str(i + 1) + ': ' + line)%0A            e = %7B'dst_file': tokens%5B0%5D, 'x': int(tokens%5B1%5D), 'y': int(tokens%5B2%5D), 'w': int(tokens%5B3%5D), 'h': int(tokens%5B4%5D)%7D%0A            #TODO: check coordinates%0A            result.append(e)%0A    return result%0A%0A%0A@click.command()%0A@click.argument('path', type=click.Path(exists=True, dir_okay=False))%0A@click.argument('info_file', type=click.Path(exists=True, dir_okay=False))%0Adef multi_cut(path, info_file):%0A    %22%22%22%0A    extract many regions from given picture by text file data%0A    %22%22%22%0A    out_dir = make_dir_by_file_name(path)%0A    img = Image.open(path)%0A    src_w = img.size%5B0%5D%0A    src_h = img.size%5B1%5D%0A    cut_info = parse_info_file(info_file, src_w, src_h)%0A    for cut in cut_info:%0A        dst_file = os.path.join(out_dir, cut%5B'dst_file'%5D)%0A        img.crop((cut%5B'x'%5D, cut%5B'y'%5D, cut%5B'x'%5D + cut%5B'w'%5D, cut%5B'y'%5D + cut%5B'h'%5D)).save(dst_file)%0A%0A%0Aif __name__ == '__main__':%0A    multi_cut()%0A

Add multi_cut script