Methods
Public Instance methods
contract method - generate the challenge
[ show source ]
# File lib/turing/image_plugins/blending.rb, line 15 15: def generate(img, word, bg = nil) # {{{ 16: if bg.nil? 17: possible = Dir[File.join(@options[:bgdir], '*')] 18: bg = possible[rand(possible.size)] 19: else 20: unless FileTest.exists?(bg) 21: raise ArgumentError, "Wrong background!" 22: end 23: end 24: 25: img_tmp = GD2::Image.load(File.open(bg, 'r')) 26: 27: if img_tmp.width < img.width || img_tmp.height < img.height 28: raise "Background has insufficient dimensions" 29: end 30: 31: img.copy_from(img_tmp, 0, 0, 0, 0, img.width, img.height) 32: 33: # XXX: equivalent of img_tmp.destroy ? 34: img_tmp = nil 35: 36: r = rand(32) 37: fg = GD2::Color[r, r, r, 40.percent] 38: 39: write_string(img, 'georgiai.ttf', fg, word, 40) 40: 41: end