[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: HTML img tags
From: |
tomas |
Subject: |
Re: HTML img tags |
Date: |
Wed, 14 Dec 2016 11:48:01 +0100 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Wed, Dec 14, 2016 at 12:51:02PM +0300, Konstantin Shakhnov wrote:
> On Sat, Dec 10, 2016 at 10:53:02AM -0600, Hikaru Ichijyo wrote:
> > Is there a mode, or some bit of Lisp code I can put in ~/.emacs, that
> > will let Emacs guess the width= and height= attributes of an image file
> > from the image itself when I create an img tag in HTML? I realize
> > there's probably no way for Emacs to do that without calling external
> > programs as a subprocess, so it's unlikely, but it would certainly be
> > convenient, and there are some HTML authoring programs that will do that
> > for you. The old KDE 3 app Quanta Plus did, but I'd rather do
> > everything in Emacs.
>
> If you have imagemagic this will work:
>
> (defun my-insert-html-image-tag (filename)
> "Insert html tag for image file"
> (interactive "fFile name: ")
> (insert
> (format "<img src=\"%s\" %s />"
> filename
> (replace-regexp-in-string
> "\n" ""
> (shell-command-to-string
> (format "identify %s | sed -r 's/^.* ([0-9]+)x([0-9]+) .*/width=\\1
> heght=\\2/'" filename))))))
Or, just "pulling in" the sed (and consolidating it with the already
present `replace-regexp-in-string'):
(replace-regexp-in-string
"^.* \\([0-9]+\\)x\\([0-9]+\\) \\(:?.\\|\n\\)*$"
"width=\\1 height=\\2"
(shell-command-to-string
(format "identify %s" filename)))
The funny construction at the end of regexp \\(:.\\|\n\\) is there
because dot alone won't match the \n. I don't know whether this
can be expressed more readably/elegantly.
regards
- -- t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
iEYEARECAAYFAlhRI2EACgkQBcgs9XrR2kagRACePjnCf2HvMgKRyTgOZJf4Kp7w
5oQAmgPsP4kypbZup6u8M+P3ff50GS0h
=U2c+
-----END PGP SIGNATURE-----
- HTML img tags, Hikaru Ichijyo, 2016/12/10
- Re: HTML img tags, Eli Zaretskii, 2016/12/10
- Re: HTML img tags, HASM, 2016/12/12
- Re: HTML img tags, James K. Lowden, 2016/12/13
- Re: HTML img tags, Lars Magne Ingebrigtsen, 2016/12/14
- Re: HTML img tags, Konstantin Shakhnov, 2016/12/14
- Re: HTML img tags,
tomas <=