Hi, all
here is the code, it works when the image has a full path, but I met
some pages which only gives relative path for images. How to handle this
condition?
Thanks a lot!
def self.get_magick_img_from_url(url)
begin
blob =''
img_file = nil
Timeout::timeout(5) {
#open web page
img_file = open(url)
}
if img_file
#read page content and store into blob
img_file.readlines().each() do |line|
blob << line
end
img_file.close()
#fetch images here
return Magick::Image.from_blob(blob)
end
rescue Timeout::Error
puts 'Timeout in get_magick_img_from_url for url - ' + url
rescue
puts 'Error in get_magick_img_from_url - ' + $!
end
return nil
end
--
Posted via http://www.ruby-forum.com/.