Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: CGI-Perl:: Location for saving the GD output

by cool (Scribe)
on Sep 10, 2006 at 17:40 UTC ( #572236=note: print w/replies, xml ) Need Help??


in reply to Re: CGI-Perl:: Location for saving the GD output
in thread CGI-Perl:: Location for saving the GD output

Dear Shmem,

I tried the third one.. and is giving output but not as image.. its all Greek and Latin..

Below are the lines of code, where I am generating the image..
my $png_data = $im->png; #open (DISPLAY,"| display -") || die; print $query->p("$tag : Free energy curve of forward strand and shu +ffle sequence"); #open (DISPLAY,">/var/www/html/upload/$tag.jpg") ||error ($query, "C +ant open GRAPH:") ; open (DISPLAY,">/tmp/upload/$tag.jpg") ||error ($query, "Cant open +GRAPH:") ; binmode DISPLAY; print DISPLAY $png_data; close DISPLAY;
and just to try with your piece of code, I am trying with this.
open (I, '<', "/tmp/upload/$tag.jpg"); #print $query->header(-content_type => "image/png"); print while <I>; close I; exit;
What u say ?? pl help!!

Replies are listed 'Best First'.
Re^3: CGI-Perl:: Location for saving the GD output
by shmem (Chancellor) on Sep 10, 2006 at 22:19 UTC
    open (DISPLAY,">/tmp/upload/$tag.jpg") ||error ($query, "Cant open +GRAPH:") ;

    Why are you appending .jpg as extension, if the image is PNG?

    binmode DISPLAY;

    Try using binmode I; for reading and binmode STDOUT for writing the file.

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
      hi Shmem,

      I tried as following...

      #!/usr/bin/perl -w use CGI; my $query = new CGI; $query->header(); $query->start_html(); print "Content-type:image/x-png\n\n"; open (I, '<', "/tmp/upload/EMBOSS_001.png"); binmode I; print while <I>; close I; $query->endform(); $query->end_html();
      But it prints only some arbitory characters, not an image!!

        What about binmode STDOUT? Further observations:

        • if you serve an image, you don't serve html.
        • you invoke the header method and throw away the result
        • you invoke the start_html method and throw away the result
        • if you assemble the header yourself (which you should not do) end it with "\r\n\r\n"
        • you invoke the endform method and throw away the result
        • you invoke the end_html method and throw away the result

        Try this:

        #!/usr/bin/perl -w use CGI; my $query = new CGI; binmode STDOUT; print $query->header(-content_type => 'image/x-png'); open (I, '<', "/tmp/upload/EMBOSS_001.png"); binmode I; print while <I>; close I;

        Does that work?

        --shmem

        _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                      /\_¯/(q    /
        ----------------------------  \__(m.====·.(_("always off the crowd"))."·
        ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://572236]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2020-09-24 20:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (135 votes). Check out past polls.

    Notices?