mirror of
https://github.com/sdsykes/fastimage.git
synced 2025-12-04 00:01:11 -05:00
detect ico type
This commit is contained in:
parent
8c2258a747
commit
b7aa051e8f
@ -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
|
||||
|
||||
BIN
test/fixtures/favicon.ico
vendored
Executable file
BIN
test/fixtures/favicon.ico
vendored
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
BIN
test/fixtures/man.ico
vendored
Normal file
BIN
test/fixtures/man.ico
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 159 KiB |
BIN
test/fixtures/test_rgb.ct
vendored
Normal file
BIN
test/fixtures/test_rgb.ct
vendored
Normal file
Binary file not shown.
14
test/test.rb
14
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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user