Rmagick file conversion

I am using rmagick to convert files stored as a tiff to either pdf or
jpg for display to the user. A snippet of test code from the controller
follows. It works OK. ( it does need a sanitizer )

require RMagick

def pdf
@sdoc = Sdoc.find(params[:id])
@fname = ‘/var/www/images/’ + @sdoc.fname
@nf = Magick::ImageList.new(@fname)
send_file ‘/tmp/ff.pdf’

What I would like to do is avoid having to save the temporary file but I
cant see how to get RMagick to do the actual conversion from tiff to pdf
without writing to a temporary file as I have done above.

I have tried a few experiments with send_data but I think the image
objects are in image magicks internal format.

I am also not clear on if I could get send_data to process a series of
jpegs stored in an rmagick imagelist.

Thank you

On Apr 5, 2006, at 8:51 PM, Steven Heimann wrote:

 @nf = Magick::ImageList.new(@fname)
 send_file '/tmp/ff.pdf'


This code won’t work in production!

Two simultaneous requests are going to produce some bad results…

Look at the Tempfile class for this sort of thing.

As for removing the need for a temporary file, look at Rails’ send_data
and RMagick’s to_blob.

– Tom M.

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