T
Timothy Hunter
Okay, I'm stumped. I've been looking at this program off-and-on for 3
days now and I can't understand why it's failing like it does. It's
*supposed* to fail, but not the way it does.
The Image#dissolve method takes 2 arguments, an Image object and a
percentage. The percentage argument can be specified either as a number
between 0.0 and 1.0, or as a string in the form "NNN%", like "50%" for
example. In this test I'm passing "1x0%" as the percentage, which is
clearly incorrect. I expect dissolve to raise an ArgumentError exception
with the message "expected percentage, got `1x0%'". What actually
happens is that I get
/Users/timothyhunter/Temporary/bug.rb:22:in `raise': can't convert
String into Integer (TypeError)
from /Users/timothyhunter/Temporary/bug.rb:22:in `dissolve'
from /Users/timothyhunter/Temporary/bug.rb:43
Line 22 is the "raise" statement.
What am I missing?
require 'RMagick'
module Magick
class Image
# Similar to `composite self -dissolve pct overlay'
# Returns composited result
def dissolve(overlay, pct)
begin
# Clamp to 0 <= pct <= 1
pct = [1.0, Float(pct)].min
pct = [0.0, pct].max
# Convert to 0 <= pct <= 100
pct = (pct * 100.0).to_i
rescue
m = pct.to_s.match(/\A(\d+)%\z/)
if m
# Clamp to 0 <= pct <= 100
pct = [100, m[1].to_i].min
pct = [0, pct].max
else
raise ArgumentError, "expected percentage, got `#{pct}'"
end
end
temp = overlay.geometry
begin
overlay.geometry = pct.to_s
res = composite(overlay, 0, 0, Magick:issolveCompositeOp)
ensure
overlay.geometry = temp
end
return res
end
end
end
# composite Flower_Hat.jpg -dissolve 90 Violin.jpg
bgnd = Magick::Image.read('Flower_Hat.jpg').first
overlay = Magick::Image.read('Violin.jpg').first
bgnd.dissolve(overlay, '1x0%').display
days now and I can't understand why it's failing like it does. It's
*supposed* to fail, but not the way it does.
The Image#dissolve method takes 2 arguments, an Image object and a
percentage. The percentage argument can be specified either as a number
between 0.0 and 1.0, or as a string in the form "NNN%", like "50%" for
example. In this test I'm passing "1x0%" as the percentage, which is
clearly incorrect. I expect dissolve to raise an ArgumentError exception
with the message "expected percentage, got `1x0%'". What actually
happens is that I get
/Users/timothyhunter/Temporary/bug.rb:22:in `raise': can't convert
String into Integer (TypeError)
from /Users/timothyhunter/Temporary/bug.rb:22:in `dissolve'
from /Users/timothyhunter/Temporary/bug.rb:43
Line 22 is the "raise" statement.
What am I missing?
require 'RMagick'
module Magick
class Image
# Similar to `composite self -dissolve pct overlay'
# Returns composited result
def dissolve(overlay, pct)
begin
# Clamp to 0 <= pct <= 1
pct = [1.0, Float(pct)].min
pct = [0.0, pct].max
# Convert to 0 <= pct <= 100
pct = (pct * 100.0).to_i
rescue
m = pct.to_s.match(/\A(\d+)%\z/)
if m
# Clamp to 0 <= pct <= 100
pct = [100, m[1].to_i].min
pct = [0, pct].max
else
raise ArgumentError, "expected percentage, got `#{pct}'"
end
end
temp = overlay.geometry
begin
overlay.geometry = pct.to_s
res = composite(overlay, 0, 0, Magick:issolveCompositeOp)
ensure
overlay.geometry = temp
end
return res
end
end
end
# composite Flower_Hat.jpg -dissolve 90 Violin.jpg
bgnd = Magick::Image.read('Flower_Hat.jpg').first
overlay = Magick::Image.read('Violin.jpg').first
bgnd.dissolve(overlay, '1x0%').display