From: Michael Morin Date: 2008-08-26T06:52:23+09:00 Subject: Re: RMagick write fails / to_blob works Gaspard Bucher wrote: > Image#write's argument is in fact a String (f.path), not the Tempfile > object itself... > >> Gaspard Bucher wrote: >>> I am trying to use @img.write(path) but it's not working (zero bytes >>> written). Using "to_blob" works. >>> >>> >>> f = Tempfile.new('tmp_img') >>> FAILING CODE: >>> @img.write(f.path) >>> >>> WORKING CODE: >>> File.open(f.path, 'wb') do |f| >>> f.syswrite(@img.to_blob) >>> end >> >> Image#write doesn't know what to do with a Tempfile object. It can only >> accept a string or a File object that's been opened for output. >> >> Image#write calls directly into ImageMagick, and ImageMagick doesn't >> know anything about Ruby objects like Tempfiles. >> -- >> Posted via http://www.ruby-forum.com/. >> > > It's possibly due to the file already being opened for writing. Try f.close first, then @img.write(f.path). -- Michael Morin Guide to Ruby http://ruby.about.com/ Become an About.com Guide: beaguide.about.com About.com is part of the New York Times Company