summaryrefslogtreecommitdiffstats
path: root/giflib-4.1.6/util/gifburst
blob: a11de763d76917203250aaa0f7ab846cd8bc6219 (plain)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/perl
#
# Split a GIF image into four or six pieces, dividing in half horizontally
# and into halves or thirds vertically.  
#
# The -s option controls the number of pieces.  The -p option controls the
# amount of overlap (in pixels) at the edges of pieces.

# Set to flush on print.
$| = 1;

require 'getopts.pl';

# How many pieces?
$split = 4;
&Getopts("s:p:");
$split = $opt_i if $opt_i;
$overlap = $opt_p if $opt_p;

$nm=$ARGV[0];
print "Bursting image $nm.gif...\n";

$stats=`giftext $nm.gif | grep Width | head -n1`;
$stats =~ /Width = ([0-9]+), Height = ([0-9]+)/;
$width=$1;
$height=$2;
print "Width is $width, height $height\n";

$overlap = 20;

if ($split == 6)
{
	$a = int($width / 2) + $overlap;
	$b = int($width / 2) - $overlap;
	$c = int($width - 1);
	$d = int($height / 3)     - $overlap;
	$e = int($height / 3) * 2 - $overlap;
	$f = int($height / 3)     + $overlap;
	$g = int($height / 3) * 2 + $overlap;
	$h = int($height - 1);

	$regions[1] = "0   0    $a   $f";
	$regions[2] = "0   $d   $a   $g";
	$regions[3] = "0   $e   $a   $h";
	$regions[4] = "$b  0    $c   $f";
	$regions[5] = "$b  $d   $c   $g";
	$regions[6] = "$b  $e   $c   $h";
}
elsif ($split == 4)
{
	$a = int($width / 2) + $overlap;
	$b = int($width / 2) - $overlap;
	$c = int($width - 1);
	$d = int($height / 2) - $overlap;
	$e = int($height / 2) + $overlap;
	$f = int($height - 1);

	$regions[1] = "0   0    $a   $e";
	$regions[2] = "0   $d   $a   $f";
	$regions[3] = "$b  0    $c   $e";
	$regions[4] = "$b  $d   $c   $f";
}
else
{
	die("I don't know how to make that many pieces.\n");
}

for ($i = 1; $i <= $split; $i++)
{
	print "${nm}-${i}: ${regions[$i]}\n";
	system("gifclip -i $regions[$i]   ${nm}.gif >${nm}-${i}.gif");
}

print "$nm done\n"