From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Newsgroups: gmane.emacs.help Subject: Re: HTML img tags Date: Wed, 14 Dec 2016 11:48:01 +0100 Message-ID: <20161214104801.GA26761@tuxteam.de> References: <8xxoa0johe9.fsf@village.keycorner.org> <20161214095101.GA8977@eee> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; x-action=pgp-signed X-Trace: blaine.gmane.org 1481712542 4449 195.159.176.226 (14 Dec 2016 10:49:02 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 14 Dec 2016 10:49:02 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Dec 14 11:48:58 2016 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cH77I-0000N2-8V for geh-help-gnu-emacs@m.gmane.org; Wed, 14 Dec 2016 11:48:56 +0100 Original-Received: from localhost ([::1]:46742 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cH77M-00086W-FR for geh-help-gnu-emacs@m.gmane.org; Wed, 14 Dec 2016 05:49:00 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51620) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cH76r-0007mJ-H7 for help-gnu-emacs@gnu.org; Wed, 14 Dec 2016 05:48:33 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cH76o-00056i-D2 for help-gnu-emacs@gnu.org; Wed, 14 Dec 2016 05:48:29 -0500 Original-Received: from mail.tuxteam.de ([5.199.139.25]:38714 helo=tomasium.tuxteam.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cH76o-00053h-5d for help-gnu-emacs@gnu.org; Wed, 14 Dec 2016 05:48:26 -0500 Original-Received: from tomas by tomasium.tuxteam.de with local (Exim 4.80) (envelope-from ) id 1cH76Q-00076f-0K for help-gnu-emacs@gnu.org; Wed, 14 Dec 2016 11:48:02 +0100 In-Reply-To: <20161214095101.GA8977@eee> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 5.199.139.25 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:111952 Archived-At: -----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 "" > 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-----