summaryrefslogtreecommitdiff
path: root/gradientgen.pl
blob: a62e8cc629a81f04f50c3751291a18656b3b8147 (about) (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
#!/usr/bin/perl
use POSIX;
use IO::File;

my @color_chars = ("1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F");

my $color1 = "#";
my $color2 = "#";

my $cct = 0;

for ( ; $cct < 8; $cct++ ){
    $color1 .= $color_chars[int(rand(14))];
}

$cct = 0;

for ( ; $cct < 8; $cct++ ){
    $color2 .= $color_chars[int(rand(14))];
}

undef $cct;
undef @color_chars;

system( "/usr/bin/convert -define gradient:angle=135 -channel RGBA -size 1920x1080 'gradient:".$color1."-".$color2."' /tmp/generated_gradient.webp" );

my $image = "";

#my $image_file = IO::File->new( "/tmp/generated_gradient.webp", "r" ) or die "Failed to read generated image";
open( my $image_file, "<", "/tmp/generated_gradient.webp" );
binmode( $iamge_file, ":utf8" );
my $image_part = "";

while ( $image_part = readline($image_file) ){
    $image .= $image_part;
}

undef $image_part;
undef $image_file;

print( "Status: 200 OK\r\n" );
print( "Content-Length: ".length($image)."\r\n" );
print( "Content-Type: image/webp; charset=utf-8\r\n\r\n" );
print( $image );

undef $image;
exit( 0 );