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
Would you consider switching to mechanize ? It can handle relative links
as well as absolute ones . With mechanize you could get all the pictures
in a very easy way .
Would you consider switching to mechanize ? It can handle relative links
as well as absolute ones . With mechanize you could get all the pictures
in a very easy way .
Thanks Lex, I will try.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.