How to fetch images from web page with relative path

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

BTW, I use rmagick.

Yi Zheng wrote:

BTW, I use rmagick.

What do you use to get the links ?

Yi Zheng wrote:

Hi Lex,

I use open-uri, any tip about this?

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 .

Hi Lex,

I use open-uri, any tip about this?

Hi All,

Get all images from given URL

Desktop Application from jazzez

Kindly go through below link and download the EXE file.

http://www.box.net/shared/m5vxqpr3r1

Install in Windows machine and enjoy with impressed images

Regards,
P.Raveendran

Lex W. wrote:

Yi Zheng wrote:

Hi Lex,

I use open-uri, any tip about this?

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.

| Privacy Policy | Terms of Service | Remote Ruby Jobs