JPEG and Perl

Discussion in 'Perl Misc' started by CSUIDL PROGRAMMEr, Aug 30, 2005.

  1. Folks
    I am new to perl
    ALl want to do is to display a image on my html page using perl .
    Here is my code

    #!/usr/bin/perl
    print "Content-type:image/jpeg\n\n";
    print " </html>";
    print "<body>";
    print " <IMG SRC='emb.jpeg'> " ;
    print "</body>";
    print"</html>";
    Is it right or am i missing something
    Thanks
     
    CSUIDL PROGRAMMEr, Aug 30, 2005
    #1
    1. Advertising

  2. CSUIDL PROGRAMMEr

    John Bokma Guest

    "CSUIDL PROGRAMMEr" <> wrote:

    > Folks
    > I am new to perl
    > ALl want to do is to display a image on my html page using perl .
    > Here is my code
    >
    > #!/usr/bin/perl


    use strict;
    use warnings;

    > print "Content-type:image/jpeg\n\n";


    use CGI;

    > print " </html>";
    > print "<body>";
    > print " <IMG SRC='emb.jpeg'> " ;
    > print "</body>";
    > print"</html>";
    > Is it right or am i missing something


    If your Content-Type is a jpeg image, why are you sending out HTML?

    --
    John Small Perl scripts: http://johnbokma.com/perl/
    Perl programmer available: http://castleamber.com/
    Happy Customers: http://castleamber.com/testimonials.html
     
    John Bokma, Aug 30, 2005
    #2
    1. Advertising

  3. CSUIDL PROGRAMMEr wrote:
    > Folks
    > I am new to perl
    > ALl want to do is to display a image on my html page using perl .
    > Here is my code


    As far as Perl is concerned some comments below

    > #!/usr/bin/perl


    You are missing
    use strict;
    use warnings;

    > print "Content-type:image/jpeg\n\n";
    > print " </html>";
    > print "<body>";
    > print " <IMG SRC='emb.jpeg'> " ;
    > print "</body>";
    > print"</html>";
    > Is it right or am i missing something


    Although technically there is nothing wrong with your Perl code (it will
    print what you are telling it to print) I would replace the phletoria of
    print statements with a single "here" document:

    use warnings;
    print <<EOT;
    Content-type:image/jpeg

    </html>
    <body>
    <IMG SRC='emb.jpeg'>
    </body>
    </html>
    EOT

    jue
     
    Jürgen Exner, Aug 30, 2005
    #3
  4. CSUIDL PROGRAMMEr

    Paul Lalli Guest

    CSUIDL PROGRAMMEr wrote:
    > Folks
    > I am new to perl


    That's okay, because this question doesn't have anything to do with
    Perl.

    > ALl want to do is to display a image on my html page using perl .
    > Here is my code
    >
    > #!/usr/bin/perl
    > print "Content-type:image/jpeg\n\n";


    Here you are telling the client (the webbrowser) that you're about to
    send a JPEG - binary data.

    > print " </html>";
    > print "<body>";


    Here, you start sending the client *text*, not a JPEG.

    > print " <IMG SRC='emb.jpeg'> " ;
    > print "</body>";
    > print"</html>";
    > Is it right or am i missing something


    You are missing something. If you want to send an HTML page that
    contains an image source link, as you seemed to do above, tell the
    client you're sending HTML:

    print "Content-type: text/html\n\n";

    If you want to send *just* the actual JPEG file, not an HTML page that
    contains a link to the file, send the actual file:

    [UNTESTED]
    if (! open my $img, '<', 'emb.jpeg') {
    print "Content-type: text/plain\n\n";
    print "Error attempting to open emb.jpeg: $!\n";
    } else {
    binmode $img;
    print "Content-type: img/jpeg\n\n";
    my $buffer;
    while (my $bytes = read ($img, $buffer, 1024) {
    print $buffer;
    }
    }

    Hope this helps,
    Paul Lalli
     
    Paul Lalli, Aug 30, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. lovaspillando
    Replies:
    0
    Views:
    1,036
    lovaspillando
    Aug 26, 2007
  2. Ivan Alameda Carballo
    Replies:
    0
    Views:
    497
    Ivan Alameda Carballo
    Aug 26, 2007
  3. Stefano Bettelli

    Request for comments on a JPEG metadata Perl module

    Stefano Bettelli, Jun 26, 2004, in forum: Perl Misc
    Replies:
    11
    Views:
    225
    Ben Morrow
    Jul 15, 2004
  4. CSUIDL PROGRAMMEr

    JPEG and Perl

    CSUIDL PROGRAMMEr, Aug 30, 2005, in forum: Perl Misc
    Replies:
    1
    Views:
    94
    James Taylor
    Aug 30, 2005
  5. Dilbert
    Replies:
    0
    Views:
    850
    Dilbert
    Nov 10, 2011
Loading...

Share This Page