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)

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


                 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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  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' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* 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:

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