Today while working on my flameshot article, I wanted to toggle inline images only where my cursor was. I was piling a ton of images and didn't want to wade through each of them.

Here's the same image in html that I toggle on org mode:


Luckily, org-toggle-inline-images
allows you to specify the beginning and end of a region:
(org-toggle-inline-images t 379 448)
And here's the code:
(defun jwow/toggle-image () "Toggle viewing the image from an org LINK at POINT if the LINK paths to an image. Otherwise, toggle all images. If the link is to an image but it does not exist, nothing will happen." (interactive) (if-let ((link-at-point (org-in-regexp org-link-bracket-re 1))) (if-let* ((link-context (org-element-context)) (local-file? (member (org-element-property :type link-context) '("attachment" "file"))) (image? (org-file-image-p (org-element-property :path link-context)))) (org-toggle-inline-images t (car link-at-point) (cdr link-at-point)) (org-toggle-inline-images t)) (org-toggle-inline-images t))) (define-key org-mode-map (kbd "C-t") #'jwow/toggle-image)
Most of the time taken to code was actually digging into ol.el
and org.el
to determine if
something was a valid image link or not.
Hope this helped!