diff --git a/lib/fastimage.rb b/lib/fastimage.rb index f9d675b..ce83d88 100644 --- a/lib/fastimage.rb +++ b/lib/fastimage.rb @@ -377,11 +377,19 @@ class FastImage :tiff when '8B' :psd + when "\0\0" + # ico has either a 1 (for ico format) or 2 (for cursor) at offset 3 + format = @stream.peek(3) + format == [0,0,1].pack('c*') ? :ico : (format == [0,0,10].pack('c*') ? :cur : nil) else raise UnknownImageType end end + def parse_size_for_ico + @stream.read(8)[6..7].unpack('CC').map{|byte| byte == 0 ? 256 : byte } + end + def parse_size_for_gif @stream.read(11)[6..10].unpack('SS') end diff --git a/test/fixtures/favicon.ico b/test/fixtures/favicon.ico new file mode 100755 index 0000000..a025090 Binary files /dev/null and b/test/fixtures/favicon.ico differ diff --git a/test/fixtures/man.ico b/test/fixtures/man.ico new file mode 100644 index 0000000..f8a6f79 Binary files /dev/null and b/test/fixtures/man.ico differ diff --git a/test/fixtures/test_rgb.ct b/test/fixtures/test_rgb.ct new file mode 100644 index 0000000..19d8af0 Binary files /dev/null and b/test/fixtures/test_rgb.ct differ diff --git a/test/test.rb b/test/test.rb index fd9a2f0..8b749e9 100644 --- a/test/test.rb +++ b/test/test.rb @@ -24,13 +24,17 @@ GoodFixtures = { "test.psd"=>[:psd, [17, 32]], "exif_orientation.jpg"=>[:jpeg, [600, 450]], "infinite.jpg"=>[:jpeg, [160,240]], - "orient_2.jpg"=>[:jpeg, [230,408]] + "orient_2.jpg"=>[:jpeg, [230,408]], + "favicon.ico" => [:ico, [16, 16]], + "man.ico" => [:ico, [48, 48]] } BadFixtures = [ "faulty.jpg", - "test.ico" + "test_rgb.ct" ] +# man.ico courtesy of http://www.iconseeker.com/search-icon/artists-valley-sample/business-man-blue.html +# test_rgb.ct courtesy of http://fileformats.archiveteam.org/wiki/Scitex_CT TestUrl = "http://example.nowhere/" @@ -74,7 +78,7 @@ class FastImageTest < Test::Unit::TestCase end def test_should_return_nil_when_image_type_not_known - assert_nil FastImage.size(TestUrl + "test.ico") + assert_nil FastImage.size(TestUrl + "test_rgb.ct") end def test_should_return_nil_if_timeout_occurs @@ -101,7 +105,7 @@ class FastImageTest < Test::Unit::TestCase def test_should_raise_when_asked_when_image_type_not_known assert_raises(FastImage::UnknownImageType) do - FastImage.size(TestUrl + "test.ico", :raise_on_failure=>true) + FastImage.size(TestUrl + "test_rgb.ct", :raise_on_failure=>true) end end @@ -157,7 +161,7 @@ class FastImageTest < Test::Unit::TestCase end def test_should_return_nil_when_image_type_not_known_for_local_file - assert_nil FastImage.size(File.join(FixturePath, "test.ico")) + assert_nil FastImage.size(File.join(FixturePath, "test_rgb.ct")) end def test_should_raise_when_asked_to_when_size_cannot_be_found_for_local_file