JPEG and Perl

C

CSUIDL PROGRAMMEr

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
 
J

John Bokma

CSUIDL PROGRAMMEr said:
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?
 
J

Jürgen Exner

CSUIDL said:
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
 
P

Paul Lalli

CSUIDL said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top