From c55e3791722e2448531791c12b15c05e62be891c Mon Sep 17 00:00:00 2001 From: mattn Date: Thu, 28 Jun 2012 22:10:27 +0900 Subject: [PATCH] fix analyzing jpeg image size. --- autoload/zencoding/util.vim | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/autoload/zencoding/util.vim b/autoload/zencoding/util.vim index 519d20c..69f3f63 100644 --- a/autoload/zencoding/util.vim +++ b/autoload/zencoding/util.vim @@ -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