emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Juan Manuel Macías" <maciaschain@posteo.net>
To: orgmode <emacs-orgmode@gnu.org>
Subject: Add color space and icc profile information to images
Date: Thu, 25 Feb 2021 23:16:47 +0100	[thread overview]
Message-ID: <878s7b23ow.fsf@posteo.net> (raw)


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
  # COLOR-INFO: Colorspace: sRGB | icc:description: Adobe RGB (1998)

  # COLOR-INFO: Colorspace: CMYK | icc:description: ISO Coated v2 300% (ECI)

  # COLOR-INFO: Colorspace: Gray | icc:description: GIMP built-in D65 Grayscale with sRGB TRC

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 ()
    (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 "
					    (format "%s"
						     "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)
	    (when (looking-at "\\(# COLOR-INFO:.+\\)")
	      (delete-region (match-beginning 0) (match-end 0)))
	    (insert (format "# COLOR-INFO: %s | %s" colorspace icc))))))))

                 reply	other threads:[~2021-02-25 22:18 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878s7b23ow.fsf@posteo.net \
    --to=maciaschain@posteo.net \
    --cc=emacs-orgmode@gnu.org \
    --subject='Re: Add color space and icc profile information to images' \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Code repositories for project(s) associated with this inbox:


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).