Relative Image

Categories

Component ID

1982982

Component name

Relative Image

Component type

module

Maintenance status

Development status

Component security advisory coverage

not-covered

Downloads

209

Component created

Component changed

Component body

This text filter rewrites the src attribute on img tags that only specify a filename to point at the current location of an attached image with the same filename should one exist.

That is, if you put this:

<img src="zebra.jpg"/>

And you've uploaded a file called zebra.jpg to an image field on the same entity, the module will replace it with something like:

<img src="/sites/foo.com/zebra.jpg"/>

I find this works quite well with Markdown. I can usually remember the filenames or know what I'll call them when I get around to uploading. From there, ![alt text](zebra.jpg) is pretty handy.

Why?

My hope is to improve on other methods of placing images in-line which, so far as I can tell, fall into two categories:

  • Bypassing Drupal entirely and using a JS file manager of some sort to upload images directly and then referring to them in img tags with /sites/brittle_path/files/image.jpg
  • Using a magic token that refers to the field id and often encodes some position, style, etc.

I like my images being available to Drupal. Not just pointed at in code but rendered as a field, with different Image Styles, that can be included in Views, change with Context, etc. Rules out the first one.

As for the second, everything seems to have its own idea of a token. In order to move between systems (whether between approaches to images in Drupal, another CMS, or a custom web app), you need to write scripts to map things. Your content is tied to the database---if ids change, the information is lost.

Ultimately, the only information needed to embed an image inline is to indicate which of the images on the node belongs where in the content. Everything else is presentation and perhaps best kept out of the content area. The filename is a natural way to select the image as it's guaranteed to be unique, otherwise Drupal wouldn't have been able to save it. img tags and filenames are pretty much the universal way to indicate which image goes where and, as a bonus, if you dump out all the nodes into a directory with the images, they just work.