Is there a solution for images organization in org-roam?

We can set “org-download-image-dir” to specific a path of the inserted image.

Is there any good idea for organization to avoid too many files in one directory?

You can do it manually with standard org mode link stuff.

  • Once your images are stored on your computer in their directory,
  • you can use org-insert-link, chose file and then autocomplete the path to your image.
  • More conveniently, in dired with you can use org-store-link
  • and then use org-insert-last-stord-link into you roam file,
  • finally calling org-redisplay-inline-image to make it visible
  • Though you would have to also manually add #+CAPTION: and stuff

Now, obviously, this could be automated with some code.

I wonder if yasnippet could not be usefull, in fact there is already a img snippet but you have to fill manually the caption and the image file path.

Otherwise I did not see any ready made package doing that…

I’ll look if I can come up with something working (it looks the level of elisp expertise isn’t too much for me…).

Came up with this little function:

(defun kym/dired-copy-images-links ()
  "Works only in dired-mode, put in kill-ring,
ready to be yanked in some other org-mode file,
the links of marked image files using file-name-base as #+CAPTION.
If no file marked then do it on all images files of directory.
No file is moved nor copied anywhere.
This is intended to be used with org-redisplay-inline-images."
  (interactive)
  (if (derived-mode-p 'dired-mode)                           ; if we are in dired-mode
      (let* ((marked-files (dired-get-marked-files))         ; get marked file list
             (number-marked-files                            ; store number of marked files
              (string-to-number                              ; as a number
               (dired-number-of-marked-files))))             ; for later reference
        (when (= number-marked-files 0)                      ; if none marked then
          (dired-toggle-marks)                               ; mark all files
          (setq marked-files (dired-get-marked-files)))      ; get marked file list
        (message "Files marked for copy")                    ; info message
        (dired-number-of-marked-files)                       ; marked files info
        (kill-new "\n")                                      ; start with a newline
        (dolist (marked-file marked-files)                   ; walk the marked files list
          (when (org-file-image-p marked-file)               ; only on image files
            (kill-append                                     ; append image to kill-ring
             (concat "#+CAPTION: "                           ; as caption,
                     (file-name-base marked-file)            ; use file-name-base
                     "\n[[file:" marked-file "]]\n\n") nil))) ; link to marked-file
        (when (= number-marked-files 0)                      ; if none were marked then
          (dired-toggle-marks)))                             ; unmark all
    (message "Error: Does not work outside dired-mode")      ; can't work not in dired-mode
    (ding)))                                                 ; error sound
1 Like

Thanks for sharing this! Mapped it to a keybinding and it works a charm. I appreciate it.