Re: JPEG and Perl



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

.



Relevant Pages

  • Re: Clickable mail link?
    ... This works okay, but ... client. ... plain-vanilla perl scripts such as the one I am describing. ... Making an email HTML is a simple as giving it a content-type header ...
    (comp.lang.perl.misc)
  • Re: RSA padding
    ... in Perl and Java. ... For Java, some of the client have to ... would be at least as good as just using the CSPRNG as a stream cipher. ...
    (sci.crypt)
  • Re: Walking a tree and extracting info... Problems
    ... Learn to use the Perl debugger and to use the ... foreach $file (@thefiles) { ... push @lines, $_; # push the data line onto the array ... Perl has allocated "@lines" once for the whole program; when you process the next file in the directory you push the lines on the bottom; the match for the HTML title then fires every time. ...
    (comp.lang.perl.misc)
  • Re: DBD Oracle 1.20 ORA-24334 Error
    ... On the premise instant client and also tried to run perl Makefile.PL -V ... the status after having connected to Oracle ... Failed 2/33 tests, 93.94% okay ...
    (perl.dbi.users)
  • Re: HTTP Filtering and Threads...
    ... You are trying to parse HTML with regular expressions. ... This is not Perl. ... # Some irrelevant code stuff... ... foreach $userID { ...
    (comp.lang.perl.misc)