Use command 'identify' to retrieve the size of a local image

* Command 'identify' is provived by ImageMagick
This commit is contained in:
Diego Pino
2013-02-07 18:32:57 +01:00
parent 8c072f6a3b
commit c088101cb7

View File

@@ -191,6 +191,11 @@ endfunction
function! zencoding#util#getImageSize(fn) function! zencoding#util#getImageSize(fn)
let fn = a:fn let fn = a:fn
if filereadable(fn) && zencoding#util#isImageMagickInstalled()
return zencoding#util#imageSizeWithImageMagick(fn)
endif
if filereadable(fn) if filereadable(fn)
let hex = substitute(system('xxd -p "'.fn.'"'), '\n', '', 'g') let hex = substitute(system('xxd -p "'.fn.'"'), '\n', '', 'g')
else else
@@ -228,3 +233,14 @@ function! zencoding#util#getImageSize(fn)
return [width, height] return [width, height]
endfunction endfunction
function! zencoding#util#imageSizeWithImageMagick(fn)
let img_info = system('identify -format "%wx%h" "'.a:fn.'"')
let img_size = split(img_info, 'x')
let width = img_size[0]
let height = substitute(img_size[1], '\n', '', '')
return [width, height]
endfunction
function! zencoding#util#isImageMagickInstalled()
return !(empty(system('command identify')))
endfunction