-
Notifications
You must be signed in to change notification settings - Fork 3
/
split_png.pl
61 lines (53 loc) · 2.62 KB
/
split_png.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use diagnostics;
use utf8;
use warnings;
use strict;
use Config::IniHash;
# Usage: split_png.pl
my $origPng = 'results/layout.png';
my $layout = ReadINI 'results/layout.ini';
# And set these values
my $x0 = 14;
my $y0 = 212;
my $height = 102;
my $width = 296;
my $dist = 14;
# And these, too
my @states = split /:/, $layout->{global}->{shiftstates};
my $isExtendMode = (( $layout->{global}->{extend_key} ) ? 1 : 0 );
my $deadkeys = 20; # it is too much, but easier to delete, than count every time...
my @filenames;
foreach (@states) {
push @filenames, 'state'.$_ if $_ != 2;
}
push @filenames, 'extend' if $isExtendMode;
foreach (1..$deadkeys)
{
push @filenames, 'deadkey'.$_;
push @filenames, 'deadkey'.$_.'sh';
}
unless ( $origPng ) {
foreach ( <*.png> ) {
if ( $origPng ) {
die 'Two png files!';
} else {
$origPng = $_;
}
}
unless ( $origPng ) {
die 'There is no png file!';
}
}
my $count = scalar @filenames;
foreach ( 0..@filenames-1 ) {
my $filename = $filenames[$_];
my $y = $y0 + ( $_ ) * ( $dist + $height );
my $newPng = 'results/' . $filename . '.png';
my $cmd = '"convert.exe" '.$origPng ." -crop ${width}x${height}+$x0+$y " . $newPng;
print $filename."\n";
system($cmd);
if ( -s $newPng < 3000 ) {
unlink $newPng;
last;
}
}