# Rmagick file conversion

**URL:** <https://www.ruby-forum.com/t/rmagick-file-conversion/56974>\
**Category:** Rails\
**Created:** [April 6, 2006, 5:51am UTC](https://www.ruby-forum.com/t/rmagick-file-conversion/56974 "2006-04-06T05:51:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steven\_Heimann](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/258eb7/32.png) [@Steven\_Heimann](https://www.ruby-forum.com/u/Steven_Heimann)\
**Post date:** [April 6, 2006, 5:51am UTC](https://www.ruby-forum.com/t/rmagick-file-conversion/56974/1 "2006-04-06T05:51:52Z")

</div>

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)  
@nf.write(’/tmp/ff.pdf’)  
send\_file ‘/tmp/ff.pdf’  
end

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  
Steven

---

<div class="post-metadata">

**Author:** ![Steven\_Heimann](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/258eb7/32.png) [@Steven\_Heimann](https://www.ruby-forum.com/u/Steven_Heimann)\
**Post date:** [April 6, 2006, 7:22am UTC](https://www.ruby-forum.com/t/rmagick-file-conversion/56974/2 "2006-04-06T07:22:31Z")

</div>

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

> ```
> @nf = Magick::ImageList.new(@fname)
> @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.
