Merge pull request #68 from michieldewit/largest_icon

For ICO files, return the largest size (by number of pixels) rather than the size of the first icon
This commit is contained in:
Stephen Sykes 2016-04-24 20:10:29 +03:00
commit 87cc1e7bdb
3 changed files with 5 additions and 2 deletions

View File

@ -463,7 +463,9 @@ class FastImage
end
def parse_size_for_ico
@stream.read(8)[6..7].unpack('CC').map{|byte| byte == 0 ? 256 : byte }
icons = @stream.read(6)[4..5].unpack('v').first
sizes = icons.times.map { @stream.read(16).unpack('C2').map { |x| x == 0 ? 256 : x } }.sort_by { |w,h| w * h }
sizes.last
end
alias_method :parse_size_for_cur, :parse_size_for_ico

BIN
test/fixtures/favicon2.ico vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

View File

@ -26,7 +26,8 @@ GoodFixtures = {
"infinite.jpg"=>[:jpeg, [160,240]],
"orient_2.jpg"=>[:jpeg, [230,408]],
"favicon.ico" => [:ico, [16, 16]],
"man.ico" => [:ico, [48, 48]],
"favicon2.ico" => [:ico, [32, 32]],
"man.ico" => [:ico, [256, 256]],
"test.cur" => [:cur, [32, 32]],
"webp_vp8x.webp" => [:webp, [386, 395]],
"webp_vp8l.webp" => [:webp, [386, 395]],