Forum: Ruby on Rails Rmagick file conversion

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Steven Heimann (Guest)
on 2006-04-06 07:51
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 =
     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
Tom M. (Guest)
on 2006-04-06 09:22
(Received via mailing list)
On Apr 5, 2006, at 8:51 PM, Steven Heimann wrote:

>      @nf =
>      @nf.write('/tmp/ff.pdf')
>      send_file '/tmp/ff.pdf'
>   end

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 topic is locked and can not be replied to.