From: Logan Capaldo Date: 2006-03-12T06:45:59+09:00 Subject: Re: cgi script send a bad image to the browser On Mar 11, 2006, at 3:43 PM, Alex wrote: > Hi everyone, > I'd like to use a ruby script to generate an image (directed graph) > and > sand it to an ajax-like javascript script that display the image in > the > browser. > I tryed to do it but what the browser display only a lot of strange > characters. I think it's a headers problem but I really don't know how > to solve it. > When I run the script in a shell and redirect the input to a file, the > generated image is good > What is the best way to send the image to the browser? > Any idea is welcome, > thanks in advance. > > Alex > > #this is the ruby script# > > require "graphviz" > g = GraphViz::new( "G" ) > main = g.add_node( "main" ) > parse = g.add_node( "parse" ) > g.add_edge( main, parse ) > puts "Content-Type: image/png" > puts > g.output( "output" => "png" ) > > ############## This is the client-side javascript to display the > gener0ated image ############## > > > ################################################ > > Maybe you want to use the CGI class. require 'cgi' cgi = CGI.new cgi.header['Content-Type'] = 'image/png' cgi.print cgi.header