#!/usr/bin/ruby

require 'rubygems'
require 'hpricot'

ext = %w( .jpg .png .gif ... )
Hpricot(DATA.read).search("img") do |img|
  name = File.basename(img.attributes['src'])
  puts name if ext.include?(File.extname(name))
end

__END__
[~]$ blah
<img src="http://host.com/foo.jpg" />
<img src="http://ruby-lang.org/something/path/to/image.jpg" />
<img src="http://google.com/PNgdvsbajkDbnm976" />