Simple way to add photos from Immich into your notes

I used to use Google Photos (and am the author of the Google Photos plugin), but I switched to Immich for reasons I mention in the readme there.

I wanted an easy way of embedding images from Immich into my notes. Originally I had planned to write a new plugin, but I 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 (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(/\/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.

Any future changes to this guide will be updated here.

1 Like

Thanks, I will probably have to consider it at some point as I end up relying a lot on Imgur with the automatic upload plugin, but it is not necessarily future-proof.
The good thing with having a plugin is to be able to copy paste an image that is automatically uploaded to whichever instance. So you can take images out from offline documents or from the internet without having to worry if the image is taken down from its original source.

I’ve been considering to copy that plugin but with Immich. The good thing is that even though it doesn’t (yet) exist on Immich’s web interface, you can add tags via API upload. So it would be easy to tag the uploaded images to be able to find/prune then later.