Insert images from Immich

I wanted an easy way of embedding images from Immich into my notes, and came up with a super quick option that only uses Templater. For me it does everything I need.

The workflow is:

  1. Browse any photo on Immich.
  2. Copy the URL or photo link.
  3. Back in Obsidian, run the template (from a hotkey). It will detect the Immich photo from the clipboard, and insert it as a thumbnail with a link back to Immich for the full-size image.

Setup

Step 1

Create an API key inside Immich, with only asset.view permissions.

Step 2

Create a new Templater template, with the following code.

  1. Replace BASE_URL with your Immich host.
  2. Replace KEY with the API key from Step 1. Double-check and make sure you have given only asset.view permissions and nothing else.
<%*
const BASE_URL = 'https://your-immich-server.com'
// An API key with asset.view permissions:
const KEY = 'API_key_with_asset_view_permission'
 
// Check the clipboard for a copied photo link
let id = getPhotoId(await tp.system.clipboard())
 
if (!id) {
  // Nothing in the clipboard, prompt for a photo link
  const link = await tp.system.prompt('Paste in an Immich photo link')
  id = getPhotoId(link)
}
 
if (id) {
  tR += `[![](${BASE_URL}/api/assets/${id}/thumbnail?size=thumbnail&apiKey=${KEY})](${BASE_URL}/photos/${id}) `
}
 
function getPhotoId (text) {
  if (!text || typeof text !== 'string') return
  
  // Is it a photo page?
  let match = text.match(/^http.*?\/photos\/(\w{8}-\w{4}-\w{4}-\w{4}-\w{12})/)
  if (match) return match[1]
 
  // Is it a direct image URL?
  match = text.match(/^http.*?\/api\/assets\/(\w{8}-\w{4}-\w{4}-\w{4}-\w{12})/)
  if (match) return match[1]
}
-%>

Step 3

If you want, set a hotkey for that template, to make it faster to insert images.

Configuration

If you want to have a larger image than the thumbnail inside your note, change size=thumbnail to be size=preview. You can do this on a per-image basis by just editing the link after the template has inserted it.

Security

Consider the case that someone gets access to your vault data and gets the value of the API key. As the API key has only asset.view permissions, there’s no way for someone to use this to discover anything about your Immich instance.

The only thing an attacker can do is view individual photos if they already know the asset ID. Without an asset ID an attacker can view nothing at all from your system.

It’s even better if you make your Immich instance only accessible from within your local network, which is how I run mine. For public sharing you can use something like Immich Public Proxy.