#!/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; srand(); for ( ; $cct < 6; $cct++ ){ $color1 .= $color_chars[int(rand(15))]; } $cct = 0; for ( ; $cct < 6; $cct++ ){ $color2 .= $color_chars[int(rand(15))]; } undef $cct; undef @color_chars; system( "/usr/bin/convert -define gradient:angle=135 -channel RGB -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( $image_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 );