I have toyed with this script for ages and couldn't work out how to get the image to display, then it came to me and thought I'd share as it took me ages searching to get the answer.
If you want to have a page with an image and the source is equal to the cgi script i.e.
in the perl you would do the following...
I have highlighted the important part, it is important to remember that you must prepare the STDOUT for binary data before printing the image content.
This example works for JPEG files, but you can easily change it for your required file type, and remember to change the MIME header content type .i.e.
Hope it helps someone
Regards, 1DMF
"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
If you want to have a page with an image and the source is equal to the cgi script i.e.
Code:
<img src="url_to_cgi/image.cgi?ID=1" />
Code:
#!/usr/bin/perl
######################
# Set Error Trapping #
######################
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
use warnings;
use strict;
##################
# Use CGI Module #
##################
use CGI;
# Set new CGI
my $cgi = new CGI;
my $id = $cgi->param('ID');
# Set file
my $file = "path_to_file/$id.jpg";
# Set Headers
print "Content-type: image/jpeg\n\n";
# Open Image File
open(FILE, "<$file") || die "Error opening image file, seek support!";
[b]# Prepare STDOUT for binary data
binmode(STDOUT);[/b]
# Print File
print <FILE>;
close(FILE);
exit();
This example works for JPEG files, but you can easily change it for your required file type, and remember to change the MIME header content type .i.e.
Code:
# GIF
print "Content-type: image/gif\n\n";
# PNG
print "Content-type: image/png\n\n";
Hope it helps someone

Regards, 1DMF
"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.