[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Image View mode and image dimensions Q
From: |
Xah |
Subject: |
Re: Image View mode and image dimensions Q |
Date: |
Sat, 11 Oct 2008 04:01:59 -0700 (PDT) |
User-agent: |
G2/1.0 |
On Oct 10, 3:14 pm, "srdjan.markov...@gmail.com"
<srdjan.markov...@gmail.com> wrote:
> Hi there!
>
> I am looking for solution to display image dimensions in Image View
> mode.
> I really like the possibility to display image in dired mode. The only
> thing I am not able to find is to retrieve the width and height of
> displayed image.
> Is there a way to do this?
(defun image-linkify ()
"Replace a path to image file with a HTML img tag.
Example, if cursor is on the word “emacs_logo.png”, then it will
became
“<img src=\"emacs_logo.png\" alt=\"emacs logo\" width=\"123\" height=
\"456\">”.
If region is active, use region as file name."
(interactive)
(let
(imgPath bds imgDimen width height altText myResult)
(setq bds
(if (and transient-mark-mode mark-active)
(cons (region-beginning) (region-end))
(bounds-of-thing-at-point 'filename)
))
(setq imgPath
(buffer-substring-no-properties (car bds) (cdr bds))
)
(if (file-exists-p imgPath)
(progn
(setq altText (file-name-nondirectory imgPath))
(setq altText (replace-regexp-in-string "\\.[A-Za-z]\\{3,4\\}$" ""
altText t t))
(setq altText (replace-regexp-in-string "_" " " altText t t))
(setq imgDimen (get-image-dimensions imgPath))
(setq width (number-to-string (car imgDimen)))
(setq height (number-to-string (car (last imgDimen))))
(setq myResult (concat "<img src=\"" imgPath "\""
" "
"alt=\"" altText "\""
" "
"width=\"" width "\" "
"height=\"" height "\">"))
(delete-region (car bds) (cdr bds))
(insert myResult)
)
(error "File does not exist")
)
))
for a full tutorial on this code, see:
http://xahlee.org/emacs/elisp_image_tag.html
Xah
∑ http://xahlee.org/
☄