From: Timothy Hunter Date: 2006-11-17T07:16:19+09:00 Subject: Re: Another IO.popen question ... Adam Groves wrote: > Hi, > > I'm wanting to create thumbnails of pdfs in png format and send them off > to be saved. I've come up with this so far: > > IO.popen("curl #{some_uri} | convert -resize 700x700 pdf:-[0] > png:-") {|f| do_something_with_this_file} > > Which works a treat. (In case you didn't know, convert is a command line > tool for ImageMagick). > > What I'd really like to do though is pass on a File object to convert: > > file = File.open("mypdf.pdf") > > IO.popen("#{file} | convert -resize 700x700 pdf:-[0] png:-") {|f| > do_something_with_this_file} > > This obviously doesn't work but I hope illustrates what I'm wanting to > acheive - namely to pass 'file' to convert it to a png which is read > back into ruby and uploaded to my file repository on S3. > > By the way, this IS for a rails application, but it seems basically like > a pure ruby question to me. > > > Regards > > Adam > > Consider RMagick: http://rmagick.rubyforge.org The Magick::Image.read method accepts an open Ruby file object as an argument. http://www.simplesystems.org/RMagick/doc/image1.html#read