fix analyzing jpeg image size.

This commit is contained in:
mattn
2012-06-28 22:10:27 +09:00
parent 8194ee6683
commit c55e379172

View File

@@ -197,20 +197,32 @@ function! zencoding#util#getImageSize(fn)
let hex = substitute(system(g:zencoding_curl_command.' "'.fn.'" | xxd -p'), '\n', '', 'g')
endif
let [type, width, height] = ['', -1, -1]
let [width, height] = [-1, -1]
if hex =~ '^89504e470d0a1a0a'
let type = 'png'
let width = eval('0x'.hex[32:39])
let height = eval('0x'.hex[40:47])
endif
if hex =~ '^ffd8'
let pos = match(hex, 'ffc[02]')
let type = 'jpg'
let height = eval('0x'.hex[pos+10:pos+11])*256 + eval('0x'.hex[pos+12:pos+13])
let width = eval('0x'.hex[pos+14:pos+15])*256 + eval('0x'.hex[pos+16:pos+17])
let pos = 4
while pos < len(hex)
let bs = hex[pos+0:pos+3]
let pos += 4
if bs == 'ffc0'
let pos += 6
let height = eval('0x'.hex[pos+0:pos+1])*256 + eval('0x'.hex[pos+2:pos+3])
let pos += 4
let width = eval('0x'.hex[pos+0:pos+1])*256 + eval('0x'.hex[pos+2:pos+3])
break
elseif bs =~ 'ffd[9a]'
break
elseif bs =~ 'ff\(e[0-9a-d]\|fe\|db\|dd\|c4\)'
let pos += (eval('0x'.hex[pos+0:pos+1])*256 + eval('0x'.hex[pos+2:pos+3])) * 2
else
let pos += 4
endif
endwhile
endif
if hex =~ '^47494638'
let type = 'gif'
let width = eval('0x'.hex[14:15].hex[12:13])
let height = eval('0x'.hex[18:19].hex[16:17])
endif