-
Notifications
You must be signed in to change notification settings - Fork 0
/
image.pl
executable file
·65 lines (53 loc) · 1.4 KB
/
image.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
62
63
64
65
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use GD;
use Getopt::Long;
use lib ".";
use Pixel;
print "--- images ---\nparameters:\n --ip --port --fork\n --img=/full/path --position=x:y\n----------\n";
my %opts;
GetOptions(
"server=s" => \$opts{server},
"ip=s" => \$opts{server},
"port=i" => \$opts{port},
"fork=i" => \$opts{forks},
"forks=i" => \$opts{forks},
"file=s" => \$opts{file},
"img=s" => \$opts{file},
"position=s" => \$opts{position},
);
my $position = $opts{position} || "0:0";
die "no --img given!" if !$opts{file};
my $image = GD::Image->new($opts{file});
my $width = $image->width;
my $height = $image->height;
my %colorHash;
for (my $x = 0; $x <= $width; $x++) {
for (my $y = 0; $y <= $height; $y++) {
my $index = $image->getPixel($x, $y);
my ($r, $g, $b) = $image->rgb($index);
my $color = Pixel::rgb2hex($r, $g, $b);
$colorHash{$x}{$y} = $color;
}
}
my ($pos_x, $pos_y) = $position =~ /^(\-?\d+):(\-?\d+)$/;
my $forks = $opts{forks} || 1;
my $PP = Pixel->new($opts{server}, $opts{port}, $forks);
sub Pixel::loop_content {
my $self = shift;
my $max_y = $self->{'max_y'};
my $max_x = $self->{'max_x'};
my $socket = $self->{'socket'};
for (my $x = 0; $x <= $width; $x++) {
for (my $y = 0; $y <= $height; $y++) {
my $color = $colorHash{$x}{$y};
my $px = $x + $pos_x;
my $py = $y + $pos_y;
$socket->send("PX $px $py $color\n");
}
}
sleep(1);
return 1;
}