Chinaunix首页 | 论坛 | 博客
  • 博客访问: 10665
  • 博文数量: 3
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 42
  • 用 户 组: 普通用户
  • 注册时间: 2011-05-12 21:28
文章分类

全部博文(3)

文章存档

2014年(3)

我的朋友
最近访客

分类: LINUX

2014-03-03 22:35:54


(require 'json)
(require 'cl)

(defvar image-magic-sh "./img_clip.sh")
(setq magic-argv '("home_bg.png" "128x128" "c_bg.png"))

(defun expend-args-to-process (cmd args)
  (apply  (append `(process-lines ,cmd) args)))

(defun make-clip-img-info ()
  (let* ((outstr) (result))
      (setq outstr  (expend-args-to-process
                            (expand-file-name image-magic-sh) magic-argv))
      (dolist (str outstr result)
        (let ((ts))
          (setq ts (split-string str " "))
          (let ( (size) (pos) (node) )
              (setq size (split-string (nth 2 ts) "x"))
              (setq pos (split-string (nth 3 ts) "x\\|+"))
              (setq size (mapcar 'string-to-number size))
              (setq pos (mapcar 'string-to-number pos))

              (setq node (list :name (file-name-nondirectory  (car ts))
                               :fmt (downcase (cadr ts))
                               :width (car size)
                               :height (cadr size)
                               :sw (car pos)
                               :sh (cadr pos)
                               :x (nth 2 pos)
                               :y (nth 3 pos)
                               :id  (string-to-number (cadr (split-string (file-name-base (car ts)) "-")))
                             ))
              (setq result (cons node result)))
          )
        )
      (message "%s" (json-encode (vconcat (sort result (lambda (x  y)
                                                         (< (plist-get x ':id) (plist-get y ':id))
                                                         )))))))

(make-clip-img-info)

阅读(2038) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~