http://qs321.pair.com?node_id=942463


in reply to Display gif in CGI page

You're confusing two kinds of scripts, one that generates HTML and one that generates an image suitable for use as the src of an img tag.

Here is a simple CGI script that simply generates a page using an image tag:

#!/usr/bin/perl use strict; use warnings; use CGI qw(:all); my $q = CGI->new; print $q->header(); print $q->start_html(); print $q->img({src => 'image.gif'}); print $q->end_html();

And here is the code you want that actually emits the conttents of an image file to be used as the image src:

#!/usr/bin/perl use strict; use warnings; use CGI qw(:all); my $q = CGI->new; print $q->header(-type => 'image/gif'); open(my $F, '<', '1.gif') || die "can not open\n"; local $\ = undef; print <$F>; close($F);

Save the 2nd script as img.pl and you can modify the first script to use your second script:

#!/usr/bin/perl use strict; use warnings; use CGI qw(:all); my $q = CGI->new; print $q->header(); print $q->start_html(); print $q->img({src => 'img.pl'}); print $q->end_html();

Notes: