CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Printing two graphics - impossible?

 



ianmac
Deleted

Mar 17, 2001, 1:56 AM

Post #1 of 7 (767 views)
Printing two graphics - impossible? Can't Post

I finally got this test program working - almost.
The graphic is printed once, and once only.
Is there some way to print more than one?

#!/usr/bin/perl

my $imagedir="/home/ianmac/graphics"; # graphics directory

print "Content-Type: image/gif\n\n"; # Header set for graphic output.

open (IMAGE, "$imagedir/digit_8.gif") || exit; # open hard-wired file

print <IMAGE>; # Print the graphic image. This works.
print <IMAGE>; # This repeat doesn't work.

close (IMAGE);
# end of script




rGeoffrey
User / Moderator

Mar 18, 2001, 9:30 PM

Post #2 of 7 (759 views)
Re: Printing two graphics - impossible? [In reply to] Can't Post

You send a header to say that an image is coming, then you send the image that the browser is expecting.

Then you send an image, but the browser is not expecting another one. You probably want to send the header again so the browser can get ready for the second image.

--
Sun Sep 9, 2001 - 1:46:40 GMT, a very special second in the epoch. How will you celebrate?


Jean
User


Mar 19, 2001, 4:12 AM

Post #3 of 7 (755 views)
Re: Printing two graphics - impossible? [In reply to] Can't Post

Just a suggestion:
Maybe you should reopen the file before second print ?


Jean Spector
QA Engineer @ Extent Technologies, Ltd.
mage@lycosmail.com


Kanji
User

Mar 19, 2001, 2:56 PM

Post #4 of 7 (750 views)
Re: Printing two graphics - impossible? [In reply to] Can't Post

Alternately, you can 'rewind' back to the beginning of the file using seek ...

Code
  print <IMAGE>; 
seek IMAGE, 0, 0;
print <IMAGE>;

... but as rGeoffrey points out, this probably won't work for what you're really trying to acheive.



ianmac
Deleted

Mar 20, 2001, 6:17 AM

Post #5 of 7 (744 views)
Re: Printing two graphics - impossible? [In reply to] Can't Post

Thanks for the suggestions, which I've tried out.
Now I've isolated the printing from the file manipulation. Now I just print an array, which just happens to be a GIF graphic. As you see, I also tried cramming two graphics into one array, in the vain hope that both would print.

#!/usr/bin/perl

my $imagedir="/home/ianmac/graphics"; # graphics directory

print "Content-Type: image/gif\n\n"; # Header set for graphic output.

open (IMAGE, "$imagedir/digit_8.gif") || exit; # open hard-wired file

my @graphic = <IMAGE>; # copy image to an array
push (@graphic, @graphic); # double the file - 2 gif pictures joined

close (IMAGE); # We no longer need it. We have a (doubled) copy

print @graphic; # prints one of the gif pictures and ignores the other half of the array

binmode STDOUT; binmode @graphic; # shouldn't be needed with a UNIX server

print @graphic; # Does nothing at all.

# end of script




ianmac
Deleted

Mar 21, 2001, 11:50 PM

Post #6 of 7 (736 views)
Re: Printing two graphics - impossible? [In reply to] Can't Post

I've found a solution that I hate.
I just use HTML to call the program multiple times.

There must be some way to do it in the perl script.




rGeoffrey
User / Moderator

Mar 26, 2001, 3:12 PM

Post #7 of 7 (720 views)
Re: Printing two graphics - impossible? [In reply to] Can't Post

The push is wasting memory. You can use @graphic as many times as you want so you don't need to hold onto a double copy of it. Also you did not add an extra header between them so you are back to where you were in the beginning with the second image not having a header and the browser ignoring it.

This should work...


Code
my $imagedir="/home/ianmac/graphics"; # graphics directory 

open (IMAGE, "$imagedir/digit_8.gif") || exit;
my @image = <IMAGE>;
close (IMAGE);

for (1..2) {
print "Content-Type: image/gif\n\n", @image;
}

--
Sun Sep 9, 2001 - 1:46:40 GMT, a very special second in the epoch. How will you celebrate?

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives