Trouble using send_data to stream image to browser

Hi

I’m doing some server-side graphics with Java2D and I’m trying to
stream the resulting image to the browser using send_data. When I try
to view the image that I streamed, the browser just shows the URL in
the window as a very small image (about .4 kb) when I am using jpeg
format. For png, it tells me that the image has errors and can’t load
it.

Here’s what I’m doing in the controller:

def sendImage
biFiltered = BI.new(100, 100, BI::TYPE_INT_RGB)
big = biFiltered.createGraphics()
$w = 0
$h = 0
begin
filename = “#{RAILS_ROOT}/public/images/kids.jpg”
imagefile = java.io.File.new(filename)
bi = javax.imageio.ImageIO.read(imagefile)
w = bi.getWidth(nil);
h = bi.getHeight(nil);
$stderr.print “after getting size”
if bi.getType != BI.TYPE_INT_RGB
bi2 = BI.new(w, h, BI::TYPE_INT_RGB)
$stderr.print “before get graphics”
big = bi2.createGraphics()
$stderr.print “after getting graphics”
big.drawImage(biFiltered, 0, 0, nil)
bi = b2
biFiltered = bi
end
rescue
$stderr.print “Couldn’t load file”
end

big.drawImage(biFiltered, 0, 0, w, h, w/0.7, w/0.7, nil)

    big.drawImage(biFiltered,

java.awt.geom.AffineTransform.getScaleInstance(2, 2), nil)
os = java.io.ByteArrayOutputStream.new
begin
isWritten = javax.imageio.ImageIO.write(biFiltered,
“jpeg”, os)
rescue
$stderr.print “Couldn’t write file”
end

    if isWritten

#send_data , :type => “image/jpeg”, :disposition =>
“inline”, :filename => newkids.jpg

       send_data "os.toByteArray", :type => "image/

jpeg", :disposition => “inline”, :filename => “scaledkids.jpg”

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs