Hello,
I keep getting an "undefined method `to_f'" for this simple script. Can
someone help me? I'm interrogating jpeg graphics files and I need to log
their widths and depths, in picas.
Thanks a lot,
Peter
Dir.chdir("T:/ioma/temp")
Dir.glob("*.jpg").each do |file|
fileinfo = `alchemy #{file} -x`
filewidth = fileinfo.match(/Width x Height: ([0-9]{1,5}) x
([0-9]{1,5})[1]/)
filedepth = fileinfo.match(/Width x Height: ([0-9]{1,5}) x
([0-9]{1,5})[2]/)
fileres = fileinfo.match(/Dots per inch: [0-9]{1,5}/)
newfilewidth = (filewidth.to_f / 200) * 6
newfiledepth = (filedepth.to_f / 200) * 6
File.open("t:/ioma/iomafiles.log", "a") { |f| f.print "#{file} width:
#{newfilewidth.to_f.round} depth: #{newfiledepth.to_f.round}\n" }
end
···
--
Posted via http://www.ruby-forum.com/.
Sorry. I meant a "to_f" there in the subject line, although it happens
with to_i, too.
Peter Bailey wrote:
···
Hello,
I keep getting an "undefined method `to_f'" for this simple script. Can
someone help me? I'm interrogating jpeg graphics files and I need to log
their widths and depths, in picas.
Thanks a lot,
Peter
Dir.chdir("T:/ioma/temp")
Dir.glob("*.jpg").each do |file|
fileinfo = `alchemy #{file} -x`
filewidth = fileinfo.match(/Width x Height: ([0-9]{1,5}) x
([0-9]{1,5})[1]/)
filedepth = fileinfo.match(/Width x Height: ([0-9]{1,5}) x
([0-9]{1,5})[2]/)
fileres = fileinfo.match(/Dots per inch: [0-9]{1,5}/)
newfilewidth = (filewidth.to_f / 200) * 6
newfiledepth = (filedepth.to_f / 200) * 6
File.open("t:/ioma/iomafiles.log", "a") { |f| f.print "#{file} width:
#{newfilewidth.to_f.round} depth: #{newfiledepth.to_f.round}\n" }
end
--
Posted via http://www.ruby-forum.com/\.
Maybe move [1] and [2] outside the regexps?
Peter
···
On Wed, May 5, 2010 at 2:45 PM, Peter Bailey <pbailey@bna.com> wrote:
Hello,
I keep getting an "undefined method `to_f'" for this simple script. Can
someone help me? I'm interrogating jpeg graphics files and I need to log
their widths and depths, in picas.
Thanks a lot,
Peter
Dir.chdir("T:/ioma/temp")
Dir.glob("*.jpg").each do |file|
fileinfo = `alchemy #{file} -x`
filewidth = fileinfo.match(/Width x Height: ([0-9]{1,5}) x
([0-9]{1,5})[1]/)
filedepth = fileinfo.match(/Width x Height: ([0-9]{1,5}) x
([0-9]{1,5})[2]/)
fileres = fileinfo.match(/Dots per inch: [0-9]{1,5}/)
to_f occurs on three lines in the code you show us. How about a clue as to
which line the error belongs to?