emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Add color space and icc profile information to images


From: Juan Manuel Macías
Subject: Add color space and icc profile information to images
Date: Thu, 25 Feb 2021 23:16:47 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)

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 via email to

[Prev in Thread] Current Thread [Next in Thread]