mirror of
https://github.com/mattn/emmet-vim.git
synced 2025-12-07 03:04:27 +08:00
fix analyzing jpeg image size.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user