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
|
#!/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(15))];
}
$cct = 0;
for ( ; $cct < 8; $cct++ ){
$color2 .= $color_chars[int(rand(15))];
}
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 = "";
open( my $image_file, "<", "/tmp/generated_gradient.webp" ) or die "Failed to open image file for reading";
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 );
|