Peter Bailey wrote:
> Dir.chdir("K:")
> tifffile  = File.basename(ARGV.to_s, ".*") + ".tif"

So "yourscript.rb c:/foo/bar.jpg" would open the file k:/bar.tif? That 
seems... wrong to me. But of course I don't know why you do this - it
might make perfect sense under the circumstances.


> info    = `tiffinfo #{tifffile}`
> width    = info.scan(/Image Width: ([0-9]{1,5})/)

String#scan creates an array of strings (if you have a regex without capturing 
groups) or of arrays (where for each capturing group you have a string in the 
array). For example:

"foo123bar456chunky789bacon".scan(/\d+/) #=> ["123","456","789"]
"hi:ho foo:bar".scan(/(\w+):(\w+)/) #=> [["hi","ho"], ["foo","bar"]]
"Image Width: 123".scan(/Image Width: ([0-9]{1,5})/) #=> [["123"]]

That's an array containing an array containing a string. Since you just want 
the string and since there's only ever gonna be one, you should just use 
String#match or String#[]:

width    = info[/Image Width: ([0-9]{1,5})/, 1]

If String#[] is used with a regex it will return the substring matching that 
regex. If you also give it a number as second argument, it will only return 
the contents of the nth capturing group (n being the number).


> I get this from Ruby:
> sizer.rb:10: undefined method `to_f' for [["5100"]]:Array
> (NoMethodError)

Yes, arrays don't have a to_f method (since arrays usually contain multiple 
elements and it would be strange to turn that into one single number).
If you use [] like I showed above, you will have a string, which will have a 
to_f method, so this will work.


HTH,
Sebastian
-- 
Jabber: sepp2k / jabber.org
ICQ: 205544826