2013-07-14 38 views
2

跟進到配置的emacs:Emacs org-display-inline-images用於顯示固定寬度的內嵌圖像

我設法顯示以下ABO血型ABO的意見內嵌圖片。現在我想爲它們設置一個固定寬度的尺寸。

設置(setq org-image-actual-width 50)不起作用。 Emacs選擇了這個變量,但它對圖像沒有任何影響。這個想法是將它們顯示爲縮略圖。

注:我在Linux上使用emacs 24.2。 我可以使用M x image-dired顯示大拇指,但是,我想在org模式下顯示固定大小的圖像。正常圖像已經顯示。

回答

2

我看了看org-display-inline-images來源: 它只是要求create-image。看來目前沒有縮放選項。

我寫了一個小的解決方法。 這有點破解,但也許你想嘗試一下。 什麼:當org想要顯示圖像「〜/ cat.jpg」, 這個函數讓它看起來是否存在「〜/ catt.png」,並顯示它。 如果沒有找到「〜/ catt.png」,ImageMagick的轉換被稱爲像這樣創建:

convert ~/cat.jpg -thumbnail 300x300 ~/catt.png 

,如果你願意,你可以自定義拇指大小,類型和名稱。 並且不要忘記安裝ImageMagick。

(defun org-display-inline-images (&optional include-linked refresh beg end) 
    "Display inline images. 
Normally only links without a description part are inlined, because this 
is how it will work for export. When INCLUDE-LINKED is set, also links 
with a description part will be inlined. This can be nice for a quick 
look at those images, but it does not reflect what exported files will look 
like. 
When REFRESH is set, refresh existing images between BEG and END. 
This will create new image displays only if necessary. 
BEG and END default to the buffer boundaries." 
    (interactive "P") 
    (unless refresh 
    (org-remove-inline-images) 
    (if (fboundp 'clear-image-cache) (clear-image-cache))) 
    (save-excursion 
    (save-restriction 
     (widen) 
     (setq beg (or beg (point-min)) end (or end (point-max))) 
     (goto-char beg) 
     (let ((re (concat "\\[\\[\\(\\(file:\\)\\|\\([./~]\\)\\)\\([^]\n]+?" 
      (substring (org-image-file-name-regexp) 0 -2) 
      "\\)\\]" (if include-linked "" "\\]"))) 
     old file ov img) 
    (while (re-search-forward re end t) 
     (setq old (get-char-property-and-overlay (match-beginning 1) 
          'org-image-overlay)) 
     (setq file (expand-file-name 
       (concat (or (match-string 3) "") (match-string 4)))) 
     (when (file-exists-p file) 
      (let ((file-thumb (format "%s%st.png" (file-name-directory file) (file-name-base file) "t.png"))) 
       (unless (file-exists-p file-thumb) 
       (shell-command (format "convert %s -thumbnail 300x300 %s" 
             file file-thumb))) 
     (if (and (car-safe old) refresh) 
      (image-refresh (overlay-get (cdr old) 'display)) 
      (setq img (save-match-data (create-image file-thumb))) 
      (when img 
     (setq ov (make-overlay (match-beginning 0) (match-end 0))) 
     (overlay-put ov 'display img) 
     (overlay-put ov 'face 'default) 
     (overlay-put ov 'org-image-overlay t) 
     (overlay-put ov 'modification-hooks 
       (list 'org-display-inline-remove-overlay)) 
     (push ov org-inline-image-overlays)))))))))) 
+0

上述方案看起來不錯,但我跟着產生拇指與所有圖像的選擇:mogrify調整大小80×80 -background白色-gravity中心-extent 80×80 -format JPG -quality 75 -path ../拇指*。*然後鏈接到原始文件。我只會導入大拇指,然後用emacs之外的標準圖像查看器打開原件。 – xyz