Andre_br has asked for the wisdom of the Perl Monks concerning the following question:

Hello my friends,

I need to print out a barcode image, generated with GD::Barcode, but I need to do it at the end of an html screen, and not as an image-only screen like below.

use GD::Barcode::ITF; binmode(STDOUT); print "Content-Type: image/png\n\n"; print GD::Barcode::ITF->new('1234567890')->plot->png;
Is there any way to do it? Eg: this one, as expected, doesn´t work:
use GD::Barcode::ITF; print "Content-Type: text/html\n\n"; print "Hello, this is the text of this screen<p>"; print GD::Barcode::ITF->new('1234567890')->plot->png;
I wait for thy help.

Thanks in advance

André

Replies are listed 'Best First'.
Re: Printing image from file, but between html
by pg (Canon) on Aug 29, 2005 at 22:00 UTC

    That obviously will not work, as the image is not of type text/html.

    Use HTML img tag.

      ... where the src is either a cgi that prints out the image directly like OP's first code, or is a temp filename (under the web root) of where the file was written out to disk.
        Hey, davidrw, that´s a good idea, thanks. I´ll point the <img src> to a sub of this script with will print out the file. This is great, because I thought I´d have to record this image to disk, what would be way too dirty.

        Thanks a lot you both

        André

Re: Printing image from file, but between html
by sgifford (Prior) on Aug 30, 2005 at 01:10 UTC
    Some browsers support a data URL that directly contains the data:
    <img src="data:image/png;base64,iVBORw0KGgoAAAANS UhEUgAAAFwAAAAWCAIAAADCTmwFAAAA3ElEQVR4nO2YwQ3DIAxFfysGKdM wRmfLGJ2GjtJDqhyKAzYBB1K/UxA2Nh/HSNxifAEA4JcAID6/w3/mfnYCI 3KOKH4Ja2GOiVUKgYlCYKIQmCgE7UXp10TV2jMhCif24NfHQZpVypVkYol St2FNr1buK9ZoCUwUgpwoU3fcI4lNUCkKZ/Pj7h4+AHhH1ouByDj1St05U 6IFOcbFoG4bby8pmQ+RceZpRjQlWpBjXAzq9ux6kB6ptOgqvDLGe/moiiK Cs/M6TYu4TutK0UyjGGuC20cf2e+j0AJG4AOYG4/WPzawWgAAAABJRU5Er kJggg==" alt="sparkline" />

    See this random page for the code I stole.

    If this is for an inhouse application where your users will be using Mozilla or Safari, this is a good solution; apparently it doesn't work in IE, though, which is kind ofa downside. :)