* Add color space and icc profile information to images
@ 2021-02-25 22:16 Juan Manuel Macías
0 siblings, 0 replies; only message in thread
From: Juan Manuel Macías @ 2021-02-25 22:16 UTC (permalink / raw)
To: orgmode
Hi,
When working with images for print, I often need to get quickly the
color space and icc profile information of each included image, so I
came up with this function (code at the end of this mail) that I share
here, in case it is useful to someone. The function inserts the
information I need, under each image link in a document. For example:
#+begin_src org
[[file:~/Imágenes/Arte/Lilian_May_Miller_Blue_Hills_and_Crescent_Moon.jpg]]
# COLOR-INFO: Colorspace: sRGB | icc:description: Adobe RGB (1998)
[[file:~/CA/CA10/cubierta.jpg]]
# COLOR-INFO: Colorspace: CMYK | icc:description: ISO Coated v2 300% (ECI)
[[file:~/Escritorio/crespo.jpg]]
# COLOR-INFO: Colorspace: Gray | icc:description: GIMP built-in D65 Grayscale with sRGB TRC
#+end_src
The only problem is that the process is somewhat slow, especially when
the images are large or there are many images in the document. I think
that this is due in part to the imagemagick process itself, and in part
to the little elegance of my function ... ;-)
Best regards,
Juan Manuel
#+begin_src emacs-lisp
(defun my-org-comment-colorspace ()
(interactive)
(save-excursion
(goto-char (point-min))
(while (re-search-forward org-bracket-link-regexp nil t)
(when (string-match (regexp-opt '(".png" ".jpg")) (match-string 1))
(forward-char -1)
(let* ((link (assoc :link (org-context)))
(link-str (when link
(buffer-substring-no-properties (cadr link) (caddr link)))))
(string-match org-bracket-link-regexp link-str)
(let* ((identify-result (shell-command-to-string
(concat "identify -verbose "
"\""
(expand-file-name
(format "%s"
(replace-regexp-in-string
"file:" ""
(substring link-str
(match-beginning 1)
(match-end 1)))))
"\"")))
(colorspace (progn
(string-match "\\(Colorspace:.+\\)" identify-result)
(substring identify-result
(match-beginning 1)
(match-end 1))))
(icc (progn
(string-match "\\(icc:description:.+\\)" identify-result)
(substring identify-result
(match-beginning 1)
(match-end 1)))))
(forward-line 1)
(beginning-of-line)
(when (looking-at "\\(# COLOR-INFO:.+\\)")
(delete-region (match-beginning 0) (match-end 0)))
(insert (format "# COLOR-INFO: %s | %s" colorspace icc))))))))
#+end_src
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-02-25 22:18 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-02-25 22:16 Add color space and icc profile information to images Juan Manuel Macías
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).