From: Xah <xahlee@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Image View mode and image dimensions Q
Date: Sat, 11 Oct 2008 04:01:59 -0700 (PDT) [thread overview]
Message-ID: <d9f200c0-9090-4102-8955-4e220cdad0c5@z18g2000prn.googlegroups.com> (raw)
In-Reply-To: c678ddab-c04e-48ab-872d-4afd33ab809e@t42g2000hsg.googlegroups.com
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/
☄
next prev parent reply other threads:[~2008-10-11 11:01 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-10 22:14 Image View mode and image dimensions Q srdjan.markovich
2008-10-10 22:48 ` Lennart Borgman
2008-10-11 11:01 ` Xah [this message]
2008-10-11 11:14 ` Xah
2008-10-11 11:48 ` Lennart Borgman
2008-10-13 12:13 ` srdjan.markovich
2008-10-13 12:16 ` srdjan.markovich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d9f200c0-9090-4102-8955-4e220cdad0c5@z18g2000prn.googlegroups.com \
--to=xahlee@gmail.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.