diff options
author | Matti Pauna <stderr64@null.net> | 2024-04-27 23:05:52 +0300 |
---|---|---|
committer | Matti Pauna <stderr64@null.net> | 2024-04-27 23:05:52 +0300 |
commit | 96913d7c96d0c4fabb030cf5b655998348a616d8 (patch) | |
tree | cfeee3a662c1d594bffc04b1bb93a542622afc41 | |
download | gradientgen-96913d7c96d0c4fabb030cf5b655998348a616d8.tar.gz gradientgen-96913d7c96d0c4fabb030cf5b655998348a616d8.tar.zst |
First commit
-rwxr-xr-x | gradientgen.pl | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/gradientgen.pl b/gradientgen.pl new file mode 100755 index 0000000..a62e8cc --- /dev/null +++ b/gradientgen.pl @@ -0,0 +1,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 ); |