Why can't I do a "to_i?"

P

Peter Bailey

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
 
P

Peter Bailey

Sorry. I meant a "to_f" there in the subject line, although it happens
with to_i, too.


Peter said:
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
 
P

Peter Hickman

[Note: parts of this message were removed to make it a legal post.]

to_f occurs on three lines in the code you show us. How about a clue as to
which line the error belongs to?
 
C

Calamitas

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|
=A0fileinfo =A0 =A0=3D `alchemy #{file} -x`
=A0filewidth =A0 =A0 =A0 =A0=3D fileinfo.match(/Width x Height: ([0-9]{1,= 5}) x
([0-9]{1,5})[1]/)
=A0filedepth =A0 =A0 =A0 =A0=3D fileinfo.match(/Width x Height: ([0-9]{1,= 5}) x
([0-9]{1,5})[2]/)
=A0fileres =A0 =A0 =A0 =A0=3D fileinfo.match(/Dots per inch: [0-9]{1,5}/)

Maybe move [1] and [2] outside the regexps?

Peter
 
P

Peter Bailey

Calamitas said:
�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}/)

Maybe move [1] and [2] outside the regexps?

Peter

Yes, thanks. I found the problem. It's the placement of my [1] and [2]
there at the end of the lines.

Thanks for your responses.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top