summaryrefslogtreecommitdiff
path: root/lisp/image/image-converter.el
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2019-09-30 06:29:27 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2019-09-30 06:29:27 +0200
commit150bf03107791cd413fa635665401a808b015b4f (patch)
tree2cf17968aff726fe798ea46830a245400031ba7b /lisp/image/image-converter.el
parent88250102707799bf961c3f1a3d80607b99502704 (diff)
downloademacs-150bf03107791cd413fa635665401a808b015b4f.tar.gz
Change the commands in image-converter--converters to lists
* lisp/image/image-converter.el (image-converter--converters): Change format of the commands to lists. (image-converter--probe, image-converter--convert): Adjust usages.
Diffstat (limited to 'lisp/image/image-converter.el')
-rw-r--r--lisp/image/image-converter.el39
1 files changed, 22 insertions, 17 deletions
diff --git a/lisp/image/image-converter.el b/lisp/image/image-converter.el
index e91d87af40d..f251d5ca590 100644
--- a/lisp/image/image-converter.el
+++ b/lisp/image/image-converter.el
@@ -43,9 +43,9 @@ installed on the system."
"A regexp that matches the file name suffixes that can be converted.")
(defvar image-converter--converters
- '((graphicsmagick :command "gm convert" :probe "-list format")
+ '((graphicsmagick :command ("gm" "convert") :probe ("-list" "format"))
(ffmpeg :command "ffmpeg" :probe "-decoders")
- (imagemagick :command "convert" :probe "-list format"))
+ (imagemagick :command "convert" :probe ("-list" "format")))
"List of supported image converters to try.")
(defun image-convert-p (file)
@@ -90,17 +90,19 @@ where created with DATA-P nil (i.e., it has to refer to a file)."
(defun image-converter--value (type elem)
"Return the value of ELEM of image converter TYPE."
- (plist-get (cdr (assq type image-converter--converters)) elem))
+ (let ((value (plist-get (cdr (assq type image-converter--converters)) elem)))
+ (if (stringp value)
+ (list value)
+ value)))
(cl-defmethod image-converter--probe ((type (eql graphicsmagick)))
"Check whether the system has GraphicsMagick installed."
(with-temp-buffer
- (let ((command (split-string (image-converter--value type :command) " "))
+ (let ((command (image-converter--value type :command))
formats)
(when (zerop (apply #'call-process (car command) nil '(t nil) nil
(append (cdr command)
- (split-string
- (image-converter--value type :probe) " "))))
+ (image-converter--value type :probe))))
(goto-char (point-min))
(when (re-search-forward "^-" nil t)
(forward-line 1)
@@ -113,13 +115,12 @@ where created with DATA-P nil (i.e., it has to refer to a file)."
(cl-defmethod image-converter--probe ((type (eql imagemagick)))
"Check whether the system has ImageMagick installed."
(with-temp-buffer
- (let ((command (split-string (image-converter--value type :command) " "))
+ (let ((command (image-converter--value type :command))
formats)
;; Can't check return value; ImageMagick convert usually returns
;; a non-zero result on "-list format".
(apply #'call-process (car command) nil '(t nil) nil
- (append (cdr command)
- (split-string (image-converter--value type :probe) " ")))
+ (append (cdr command) (image-converter--value type :probe)))
(goto-char (point-min))
(when (re-search-forward "^-" nil t)
(forward-line 1)
@@ -134,8 +135,9 @@ where created with DATA-P nil (i.e., it has to refer to a file)."
(with-temp-buffer
(let ((command (image-converter--value type :command))
formats)
- (when (zerop (call-process command nil '(t nil) nil
- (image-converter--value type :probe)))
+ (when (zerop (apply #'call-process (car command) nil '(t nil) nil
+ (append (cdr command)
+ (image-converter--value type :probe))))
(goto-char (point-min))
(when (re-search-forward "^ *-" nil t)
(forward-line 1)
@@ -161,7 +163,7 @@ where created with DATA-P nil (i.e., it has to refer to a file)."
(image-converter--convert-magick type file))
(defun image-converter--convert-magick (type file)
- (let ((command (split-string (image-converter--value type :command) " ")))
+ (let ((command (image-converter--value type :command)))
(unless (zerop (apply #'call-process (car command)
nil t nil
(append (cdr command)
@@ -172,11 +174,14 @@ where created with DATA-P nil (i.e., it has to refer to a file)."
(cl-defmethod image-converter--convert ((type (eql ffmpeg)) file)
"Convert using ffmpeg."
- (unless (zerop (call-process (image-converter--value type :command)
- nil '(t nil) nil
- "-i" (expand-file-name file)
- "-c:v" "png" "-f" "image2pipe" "-"))
- "ffmpeg error when converting"))
+ (let ((command (image-converter--value type :command)))
+ (unless (zerop (apply #'call-process
+ (car command)
+ nil '(t nil) nil
+ (append (cdr command)
+ (list "-i" (expand-file-name file)
+ "-c:v" "png" "-f" "image2pipe" "-"))))
+ "ffmpeg error when converting")))
(provide 'image-converter)