#!/usr/bin/perl -wT use strict; # types where extension <> content-type my %types = qw(jpg jpeg tif tiff); # get an array of image-files my @images = glob("./images/*"); die "No images found\n" unless scalar @images; # choose an image and and prepare content type extension my $image = $images[int(rand @images)]; die "No extension for $image\n" unless $image =~ /\.(.+)$/; my $ctype = $1; $ctype = $types{$ctype} if exists $types{$ctype}; # read and print image open(IMG, $image)||die "Cannot open $image:$!\n"; print "Content-type: image/$ctype\n\n"; binmode (IMG); binmode (STDOUT); print while(); close IMG;