15

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?

7
  • If I understand correctly this is a feature of github own org exporter, not of org-mode in emacs.
    – JeanPierre
    Commented Sep 3, 2016 at 20:52
  • Ah. My bad. Hmm... any ideas how to get this to work in org-mode?
    – Adam
    Commented Sep 3, 2016 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
    Commented Feb 11, 2017 at 21:58
  • Sure! What have you got?
    – Adam
    Commented Feb 12, 2017 at 1:55
  • @Adam I just tried [[https://link][https://image]] and it worked here. But not with local files.
    – hraban
    Commented Jun 28, 2021 at 23:13

2 Answers 2

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)}}}
2
  • 1
    Note: This doesn't work when viewed in emacs, and presumably needs to be exported to HTML.
    – HappyFace
    Commented Oct 7, 2020 at 10:52
  • I guess this works, but at this point I would just use #+export_html... and write the raw <a href..><img ... myself :/
    – hraban
    Commented Aug 24, 2023 at 18:43
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.

2
  • 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: w3schools.com/tags/tryit.asp?filename=tryhtml_link_image
    – Adam
    Commented Sep 4, 2016 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
    Commented Sep 4, 2016 at 14:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.