Bill Lovett

Automating HTML Image Tags in Emacs

The Problem

To write an image tag, you need to know the width and height of the image. Determining those numbers forces you to leave Emacs and consult another application such as Photoshop or your file manager. Locating the target file is a timesink, as is typing the height, width, and alt attributes. Omitting the width and height can have undesireable side effects and is not a best practice.

The Solution

The function first prompts you for the image file. The usual autocompletion features are in effect, so the typing shouldn't be too onerous. Other than alt text, everything else is automatic. Emacs is figuring out the image width and height on its own, so there's no reliance on third-party tools.

References

  1. Elisp Lesson: Writing image-linkify Function

Revisions

  • August 8, 2009: Added missing code for relpath function, which is used by img-tag