14

I want to create clickable image links in org-mode. This would be equivalent to:

<a href="path-to-file">
   <img src="path-to-image">
</a>

Currently, I can display inline image previews just fine, with [[path-to-image]] followed by org-toggle-inline-images. What I would like to do now, is add support for [[path-to-file][path-to-image]].

Any ideas?

Drew
  • 75,699
  • 9
  • 109
  • 225
Adam
  • 1,857
  • 11
  • 32
  • If I understand correctly this is a feature of github own org exporter, not of org-mode in emacs. – JeanPierre Sep 03 '16 at 20:52
  • Ah. My bad. Hmm... any ideas how to get this to work in org-mode? – Adam Sep 03 '16 at 21:12
  • To clarify, your ideal answer would add support for `[[path-to-file][path-to-image]]` but would you accept a workaround until that feature is added to the exporter? – Melioratus Feb 11 '17 at 21:58
  • Sure! What have you got? – Adam Feb 12 '17 at 01:55
  • @Adam I just tried `[[https://link][https://image]]` and it worked here. But not with local files. – hraban Jun 28 '21 at 23:13
  • Scratch that--it also seems to work for local files, as long as I explicitly use the `file:` protocol. What version of org were you using? Have you tried this recently? – hraban Jun 28 '21 at 23:19
  • I'm unable to comment, so that's why I'm creating the answer. Anyway in OrgMode 9.6 `[[https://link][file:image]]` is working to create image link in case there is no spaces in path to image. If anyone know how to solve the error when they are spaces, it would be good too. – vondravl Aug 10 '23 at 09:04

2 Answers2

6

It can be be done using a macro:

#+MACRO: imglnk @@html:<a href="$1"><img src="$2"></a>@@

This is an image link: {{{imglnk(path-to-file,path-to-image)}}}
Francesquini
  • 161
  • 1
  • 3
2

Org Mode already supports embedding images in exported HTML.

The inline preview functionality does not work for remote images (i.e. those found on the internet). See the question about this. Preview does work for local images, as I think you already know.

Tianxiang Xiong
  • 3,848
  • 16
  • 27
  • 5
    Thanks. Yes, I can get an image to display in the buffer just fine. But what I want to do is Create an image link so that clicking on the inline image opens a separate file (or URL). For example, embedding a screen grab from a video and then clicking it plays a QuickTime file. The html equivalent can be found here: http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_link_image – Adam Sep 04 '16 at 14:15
  • 3
    So something like this [[file:movie.mp4][file:screengrab.png]] where the screen grab is previewed in the buffer and on clicking it, the movie file opens in its default application. – Adam Sep 04 '16 at 14:21