From afbcac04b4dfac3029404c5d5762652e39f7c6b0 Mon Sep 17 00:00:00 2001 From: mattn Date: Thu, 13 May 2010 10:06:50 +0900 Subject: [PATCH] add the pure vimscript code for 'get image size'. you can use it without perl interface just now. --- zencoding.vim | 55 ++++++++++++++++++++++----------------------- zencoding.vim.vimup | 4 +++- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/zencoding.vim b/zencoding.vim index 2d505b9..ea5cf4f 100644 --- a/zencoding.vim +++ b/zencoding.vim @@ -1,8 +1,8 @@ "============================================================================= " File: zencoding.vim " Author: Yasuhiro Matsumoto -" Last Change: 11-May-2010. -" Version: 0.39 +" Last Change: 13-May-2010. +" Version: 0.40 " WebPage: http://github.com/mattn/zencoding-vim " Description: vim plugins for HTML and CSS hi-speed coding. " SeeAlso: http://code.google.com/p/zen-coding/ @@ -1506,37 +1506,36 @@ function! s:zen_imageSize() if fn !~ '^\(/\|http\)' let fn = simplify(expand('%:h') . '/' . fn) endif - let [w, h] = [-1, -1] + let [type, width, height] = ['', -1, -1] - if has('perl') -perl <{width} || -1, $ii->{height} || -1)); - undef $ii; -}; -VIM::Msg($@, "ErrorMsg") if $@; -EOF + if filereadable(fn) + let hex = substitute(system('xxd -p "'.fn.'"'), '\n', '', 'g') + else + let hex = substitute(system('curl -s "'.fn.'" | xxd -p'), '\n', '', 'g') endif - if w == -1 && h == -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]) + endif + if hex =~ '^47494638' + let type = 'gif' + let width = eval('0x'.hex[18:19].hex[16:17]) + let height = eval('0x'.hex[14:15].hex[12:13]) + endif + + if width == -1 && height == -1 return endif - let current.attr.width = w - let current.attr.height = h + let current.attr.width = width + let current.attr.height = height let html = s:zen_toString(current, 'html', 1) call s:change_content(img_region, html) endfunction diff --git a/zencoding.vim.vimup b/zencoding.vim.vimup index 186816c..928c1c7 100644 --- a/zencoding.vim.vimup +++ b/zencoding.vim.vimup @@ -2,7 +2,7 @@ script_name: ZenCoding.vim script_id: '2981' script_type: utility script_package: zencoding.vim -script_version: '0.39' +script_version: '0.40' required_vim_version: '7.0' summary: vim plugins for HTML and CSS hi-speed coding. @@ -95,6 +95,8 @@ install_details: | copy zencoding.vim to your plugin directory. versions: +- '0.40': | + This is an upgrade for ZenCoding.vim: add the pure vimscript code for 'get image size'. you can use it without perl interface just now. - '0.39': | This is an upgrade for ZenCoding.vim: fixed problem about 'selection'. see http://github.com/mattn/zencoding-vim/issues/#issue/2 - '0.38': |