PicCrop is an open source Python application to crop sub-pictures from parent pictures. This tool also allows format-converting from a corp-list file to a YAML layout file.
A crop-list file lists parent pictures and describes sub-pictures to crop.
A YAML layout file describes multiple picture layouts of screens. I invented the syntax under the standard YAML and used to assemble separated sub- pictures into whole-pictures.
- Download a binary distribution of PicCrop (e.g., PicCrop-1.1-bin.zip) from Downloads page.
- Uncompress the binary distribution.
- Install PicCrop.
- Copy source (parent) pictures to the screen folder.
- Edit crop.lst
- Run
rect.bat
to draw rectangles listing in crop.lst. - Run
crop.bat
to crop sub-pictures from source pictures. - Run
yaml.bat
to convert the crop-list file (i.e., crop.lst) to the YAML file (i.e., layout_coord.yaml).
- Batch files rect.bat, crop.bat, and yaml.bat can be run in any order.
- Result pictures of rect.bat are put into out folder.
- Generated sub-pictures are put into out folder.
- Run
clean.bat
to remove the generated files
A crop.lst looks like as follows:
# section 1
parent1.png
0, 0, 50, 50, crop1-1.png
50, 50, 12, 34, crop1-2.png
# section 2
parent2.png
0, 1, 30, 40, "crop 2-1.png" # support filename with quoted string
90 50 33 44 crop2-2.png # support space separating
50, 50, 33, 22, crop2-3.png
# section 3
parent3.png
0, 1, 30, 40, crop3-1.png
90, 50, 33, 44, crop3-2.png
50, 50, 33, 22, crop3-3.png
- A crop-list file can list multiple original-subpicture sections.
- Each section begins with a original picture filename (e.g., parent1.png), and describes multiple statements of sub-pictures (e.g., crop1-1.png).
- Each sub-picture statement lists an area (i.e., x, y, w, h) and a target filename.
- Symbol
#
is the comment prefix.
Let's say that I want to crop icons and texts from the iPod touch photograph named ipod-touch-5th-black.png:
# source file to crop out 4 icons
#--------------------------------
ipod-touch-5th-black.png
# x, y, w, h, target file
#------------------------------------
117, 139, 62, 62, ico_FaceTime.png
190, 139, 62, 62, ico_Calendar.png
263, 139, 62, 62, ico_Photos.png
336, 139, 62, 62, ico_Camera.png
# source file to crop out 4 texts
#--------------------------------
ipod-touch-5th-black.png
# x, y, w, h, target file
#------------------------------------
112, 203, 70, 15, txt_FaceTime.png
185, 203, 70, 15, txt_Calendar.png
258, 203, 70, 15, txt_Photos.png
331, 203, 70, 15, txt_Camera.png
ipod-touch-5th-black.png_1.png:
- The above picture marks the icon areas with red rectangles.
ipod-touch-5th-black.png_2.png:
- The above picture marks the text areas with red rectangles.
icon pictures:
text pictures:
# Generated by the Picture Crop v1.0
# !author: Jiang Yu-Kuan <[email protected]>
# !trail: crop.py yaml -olayout_coord.yaml crop.lst
---
name: ipod-touch-5th-black
layout: {kind: coordinate}
align: left
parts:
- {image: ico_FaceTime.png, coord: [117, 139]}
- {image: ico_Calendar.png, coord: [190, 139]}
- {image: ico_Photos.png, coord: [263, 139]}
- {image: ico_Camera.png, coord: [336, 139]}
---
name: ipod-touch-5th-black
layout: {kind: coordinate}
align: left
parts:
- {image: txt_FaceTime.png, coord: [112, 203]}
- {image: txt_Calendar.png, coord: [185, 203]}
- {image: txt_Photos.png, coord: [258, 203]}
- {image: txt_Camera.png, coord: [331, 203]}
...
usage: crop.exe [-h] [-v] {crop,yaml} ...
positional arguments:
{crop,rect,yaml} commands
crop Crop out pictures according to a crop-list file.
rect Mark out rectangles from a crop-list file.
yaml Generate a YAML file of screens with coordinate layouts.
optional arguments:
-h, --help show this help message and exit
-v, --version show program's version number and exit
usage: crop.exe crop [-h] [-s <directory>] [-o <directory>] crop-list-file
positional arguments:
crop-list-file The crop list file.
optional arguments:
-h, --help show this help message and exit
-s <directory>, --screen_dir <directory>
assign a <directory> to read screen pictures. The
default directory is "screen".
-o <directory>, --out_dir <directory>
assign a <directory> to store output cropped
pictures. The default directory is "out".
usage: crop.exe rect [-h] [-s <directory>] [-o <directory>] crop-list-file
positional arguments:
crop-list-file The crop list file.
optional arguments:
-h, --help show this help message and exit
-s <directory>, --screen_dir <directory>
assign a <directory> to read screen pictures. The
default directory is "screen".
-o <directory>, --out_dir <directory>
assign a <directory> to store output screen pictures.
The default directory is "out".
usage: crop.exe yaml [-h] [-o <file>] crop-list-file
positional arguments:
crop-list-file The crop list file.
optional arguments:
-h, --help show this help message and exit
-o <file>, --output <file>
place the output into <file>, the YAML file (default
"layout_coord.yaml").