From: "Bashar A. Asad" Date: 2001-12-27T20:35:23+09:00 Subject: [ruby-talk:29469] Re: imageMagick hi, thanks for the reply I tried it without #{} thingy and this is what came up with dir = "." def no_ext(n) n.sub(/\.gif/,'') end def createThumbFile(f) img = Magick::Image.new(f) img.scale('60%') n = no_ext(f) img.write("filename"=>f+"thumb.gif") end Dir.foreach(dir){|file| createThumbFile(file) } and didn't work, the error message below ----------------------------------------------------------------- /usr/lib/ruby/1.6/magick.rb:63: warning: Unable to open file: . (330) /usr/lib/ruby/1.6/magick.rb:31:in `initialize': no implicit conversion from boolean (TypeError) from /usr/lib/ruby/1.6/magick.rb:31:in `new' from /usr/lib/ruby/1.6/magick.rb:31:in `parse_image_geometry' from /usr/lib/ruby/1.6/magick.rb:192:in `scale' from ./resize.rb:15:in `createThumbFile' from ./resize.rb:21 from ./resize.rb:20:in `foreach' from ./resize.rb:20 On Thursday 27 December 2001 06:24, you wrote: > Hello -- > > On Thu, 27 Dec 2001, Bashar A. Asad wrote: > > hello again, > > I tried to write the script that will read img file and create thumbs > > from the dir, and this is what I came up with but its not working, it > > spells out a parse error on n = no_ext(#{f}), what am I doing wrong? > > Well, you've started a comment at a very strange place :-) > > I think you mean: > > no_ext(f) > > don't you? > > Also: > > require "magick" > > > > dir = "." > > > > def no_ext(n) > > r="#{n}" > > Why not just: r = n > > > r.sub(/\.gif/,'') > > If that's all that r exists for, then you could do just: > > def no_ext(n) > n.sub(/\.gif$/, '') > end > > which won't do any damage to n. > > > end > > > > > > def createThumbFile(f) > > img = Magick::Image.new(#{f}) > > Here, again, #{f} isn't what you mean: > > img = Magick::Image.new(f) > > > img.scale('60%') > > n = no_ext(#{f}) > > img.write("filename"=>"#{n}_thumb.gif") > > end > > > > Dir.foreach(dir){|file| > > createThumbFile("file") > > } > > "file" (in quotation marks) isn't going to give you the name of the > file -- it's going to give you the word "file" every time. > > > David