Send_file but not send_data?

So this is the original code I used, and it worked

send_file ‘vendor/sprites/not-found.png’, {:filename =>
“sprite-not-found.png”, :type => “image/png”, :disposition => “inline”}

Now I switched it to this (going to be adding imageMagick)

send_data File.read(‘vendor/sprites/not-found.png’), {:filename =>
“soldier-not-found.png”, :type => “image/png”, :disposition => “inline”}

But now instead of seeing my image I see the good 'ol broken image. I
assume this is because an image is binary but File.read() uses String.
How would I go about loading an image into RAM and serve it?

Also would it just be better for me to make the image, cache it, then
use send_file to it instead of send_data?

On Nov 3, 8:21pm, Mohammad El-abid [email protected] wrote:

But now instead of seeing my image I see the good 'ol broken image. I
assume this is because an image is binary but File.read() uses String.
How would I go about loading an image into RAM and serve it?

a String in ruby is just a collection of bytes - there isn’t a
separate binary type. If you’re on windows you might need to open the
file in binary mode

Fred

Yes I am on Windows, haven’t felt a need to get onto Ubuntu yet. So I
was able to get it working now! Can anyone recommend libraries for
pasting together multipliable images? e.g. I have body, arms, legs, etc
images and want to put them all ontop of each other. I do not believe
that I need to move them. (I’ve heard rMagick but it’s not too windows
friendly, hoping to find something else that’s pure ruby)

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