From: Rolf H. <rh...@fl...> - 2008-02-15 17:41:16
|
Hi Mauricio, if you don't want to add additional information to the image (like we do at our site) you can send back the decoded image also directly. Just replace "Content-type: text/html\n\n" by "Content-type: image/jpeg\n\n" and then print the image data instead of the "<IMG>" tag with "print $decoded;" This will make the script more simple and it will also spare you to take care of the accumulating images on the server. (Note: "image/jpeg" worked in all browsers I tested but "image/jpg" failed in Safari on a Mac.) And I included the three hidden input tags "IDB_ID", "IMAGE_WIDTH" and "IMAGE_HEIGHT" only for annotation purposes. So they are obsolete in your example. Regards, Rolf Mauricio Carrillo Tripp wrote: > Many thanks to Rolf Huehne and Bob Hanson for their tips on this question. > As a follow up and for completeness, in case someone looks for it later, > here's the full answer in code: > > *HTML file and Javascript (client side)* > > <html> > <head> > <script type="text/javascript"> > function get_snapshot() > { > var BI = document.getElementById("bounce_image"); > var BI_D = document.getElementById("IMAGE_DATA"); > var BASE64 = jmolGetPropertyAsString("image"); > BI_D.value = BASE64; > BI.submit(); > } > </script> > </head> > <body> > <script type="text/javascript"> > jmolInitialize("jmol/"); > jmolApplet(350,"load something.pdb"); > </script> > <input class="jmol_snapshot" type="button" id="snapshot" value="snapshot" > onclick='get_snapshot()'> > <form id="bounce_image" action=" > http://MY.SERVER.COM/cgi-bin/decode_snapshot.pl" method="post" > target="_blank"> > <input type="hidden" id="IDB_ID" name="IDB_ID" value="some > id"> > <input type="hidden" id="IMAGE_WIDTH" name="IMAGE_WIDTH" > value="350"> > <input type="hidden" id="IMAGE_HEIGHT" name="IMAGE_HEIGHT" > value="350"> > <input type="hidden" id="IMAGE_DATA" name="IMAGE_DATA" > value="empty"> > </form> > </body> > </html> > > *PERL script (server side) file 'decode_snapshot.pl'* > > #!/usr/bin/perl > use MIME::Base64; > print "Content-type: text/html\n\n"; > %postFields = (); > read( STDIN, $tmpStr, $ENV{ "CONTENT_LENGTH" } ); > @parts = split( /\&/, $tmpStr ); > foreach (@parts) { > s/%([0-9A-F][0-9A-F])/pack("c",hex($1))/ge; > ( $name, $value ) = split(/\=/); > $postFields{ "$name" } = $value; > } > $decoded = decode_base64($postFields{"IMAGE_DATA"}); > open (MYFILE, '>path_to_file/jmol_snapshot.jpg'); > print MYFILE $decoded; > close (MYFILE); > print "<img src='path_to_file/jmol_snapshot.jpg' />"; > exit; > > > This should work in all browsers. > > > PS Codes can be further optimized, I guess, but the way they are written now > > makes it pretty clear how they work... > > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > > > ------------------------------------------------------------------------ > > _______________________________________________ > Jmol-users mailing list > Jmo...@li... > https://lists.sourceforge.net/lists/listinfo/jmol-users |