Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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

by shmem (Chancellor)
on Sep 10, 2006 at 22:19 UTC ( #572256=note: print w/replies, xml ) Need Help??


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

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}

Replies are listed 'Best First'.
Re^4: CGI-Perl:: Location for saving the GD output
by cool (Scribe) on Sep 11, 2006 at 06:38 UTC
    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}
        Ya Shmem,

        it is working finally..Thanks a lot :-) ; but if you remember I asked the question that I was not able to get (B). Where (B) was actually this png image and (A) was text output.

        And with (A) and (B) together I am still getting Greek and Latin only.

        Is it a problem of header, because to get both text as well as image.. which header should I use.. I tried every combination of

        print "Content-type:text/html\r\n\r\n"; print "Content-type:image/x-png\r\n\r\n; but its printing the same arbitory symbols.. Or both the things can not be worked simultaneously??

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2020-03-29 00:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    To "Disagree to disagree" means to:









    Results (168 votes). Check out past polls.

    Notices?