(and auto
(or (eq auto t) (image-type-available-p type)))))
+(defvar image-convert-to-format)
;;;###autoload
(defun create-image (file-or-data &optional type data-p &rest props)
(when (eq type 'image-convert)
(require 'image-converter)
(setq file-or-data (image-convert file-or-data data-format)
- type 'png
+ type (intern image-convert-to-format)
data-p t)))
(when (image-type-available-p type)
(let ((image
:type 'symbol
:version "27.1")
+(defcustom image-convert-to-format "png"
+ "The image format to convert to.
+This should be a string like \"png\" or \"ppm\" or some
+other (preferrably lossless) format that Emacs understands
+natively. The converter chosen has to support the format, and if
+not, conversion will fail."
+ :group 'image
+ :version "29.1"
+ :type 'string)
+
(defvar image-converter-regexp nil
"A regexp that matches the file name suffixes that can be converted.")
'image-convert))
(defun image-convert (image &optional image-format)
- "Convert IMAGE file to the PNG format.
+ "Convert IMAGE file to an image format Emacs understands.
+This will usually be \"png\", but this is controlled by the
+`image-convert-to-format' user option.
+
IMAGE can either be a file name or image data.
To pass in image data, IMAGE should a string containing the image
IMAGE can also be an image object as returned by `create-image'.
-This function converts the image to PNG, and the converted image
-data is returned as a string."
+This function converts the image the preferred format, and the
+converted image data is returned as a string."
;; Find an installed image converter.
(unless image-converter
(image-converter--find-converter))
(if (listp image)
;; Return an image object that's the same as we were passed,
;; but ignore the :type value.
- (apply #'create-image (buffer-string) 'png t
+ (apply #'create-image (buffer-string)
+ (intern image-convert-to-format)
+ t
(cl-loop for (key val) on (cdr image) by #'cddr
unless (eq key :type)
append (list key val)))
(list (format "%s:-"
(image-converter--mime-type
image-format))
- "png:-"))))
+ (concat image-convert-to-format
+ ":-")))))
;; SOURCE is a file name.
(apply #'call-process (car command)
nil t nil
(append (cdr command)
- (list (expand-file-name source) "png:-")))))
+ (list (expand-file-name source)
+ (concat image-convert-to-format
+ ":-"))))))
;; If the command failed, hopefully the buffer contains the
;; error message.
(buffer-string))))
(append
(cdr command)
(list "-i" "-"
- "-c:v" "png"
+ "-c:v" image-convert-to-format
"-f" "image2pipe" "-"))))
(apply #'call-process
(car command)
nil '(t nil) nil
(append (cdr command)
(list "-i" (expand-file-name source)
- "-c:v" "png" "-f" "image2pipe"
+ "-c:v" image-convert-to-format
+ "-f" "image2pipe"
"-")))))
"ffmpeg error when converting")))