3
# For faster multiple execs, start a gimp, and do Xtns/Perl/Server.
5
# Warning! Error message are the worst ever. Unquote the "set_trace" if you need troubleshooting.
8
$ARGV[0] && -r $ARGV[0] && $ARGV[1] && !$ARGV[2] or
9
die "Usage: create <base_image> <number_steps_each_side>\n";
12
#- (gc) this shit wasted me something like 2 hours: opposedly to what's
13
#- claimed in the doc, we need to precise `:auto' in the imports, grrrrr..
14
use Gimp qw(:consts main xlfd_size :auto);
17
#Gimp::set_trace(TRACE_ALL);
19
print "Using base file <$ARGV[0]> with <$ARGV[1]> steps each side.\n";
27
my ($filename, $step, $max) = @_;
30
eval { $img = gimp_file_load($filename, $filename) };
32
die "Failed to load <$filename> into a Gimp image ($@).\n";
35
my $w = gimp_image_width($img);
36
my $h = gimp_image_height($img);
38
my $rot = gimp_rotate(gimp_image_active_drawable($img), 1, 3.1415926535897932384626433832795028841972/2 * (-$step)/$max);
40
#- dunno why, interactive "rotate" keeps same width/height, this one not.. this is beautiful
41
gimp_crop($img, $w, $h, 0, 0);
43
$filename =~ s/\.([^\.]+)/_$step.$1/;
45
#- now we want to crop the image a maximum, to reduce time of drawing in the game
46
my @pixels = gimp_drawable_get_pixel($rot, $w-1, $h-1);
48
#- since I need to know which shift this crop produced, first I forbid croping right and bottom...
49
gimp_drawable_set_pixel($rot, $w-1, $h-1, 4, [255, 255, 255, 255]);
50
plug_in_autocrop($img, $rot);
52
#- ...and I measure shift...
53
$data .= sprintf "$step %d %d\n", $w-gimp_image_width($img), $h-gimp_image_height($img);
55
#- ...and now I can finally crop the rest of the image
56
gimp_drawable_set_pixel($rot, gimp_image_width($img)-1, gimp_image_height($img)-1, 4, \@pixels);
57
plug_in_autocrop($img, $rot);
59
gimp_file_save($img, $rot, $filename, $filename);
63
foreach my $step (0..$ARGV[1]) {
65
rot($ARGV[0], $step, $ARGV[1]);
67
rot($ARGV[0], -$step, $ARGV[1]);
70
open DAT, ">data" or fail_with_message("Can't open data for writing.");