Function: image-type
image-type is an autoloaded and byte-compiled function defined in
image.el.gz.
Signature
(image-type SOURCE &optional TYPE DATA-P)
Documentation
Determine and return image type.
SOURCE is an image file name or image data. Optional TYPE is a symbol describing the image type. If TYPE is omitted or nil, try to determine the image type from its first few bytes of image data. If that doesn't work, and SOURCE is a file name, use its file extension as image type.
Optional DATA-P non-nil means SOURCE is a string containing image
data. If DATA-P is a symbol with a name on the format
image/jpeg, that may be used as a hint to determine the image
type if we can't otherwise guess it.
Source Code
;; Defined in /usr/src/emacs/lisp/image.el.gz
;;;###autoload
(defun image-type (source &optional type data-p)
"Determine and return image type.
SOURCE is an image file name or image data.
Optional TYPE is a symbol describing the image type. If TYPE is omitted
or nil, try to determine the image type from its first few bytes
of image data. If that doesn't work, and SOURCE is a file name,
use its file extension as image type.
Optional DATA-P non-nil means SOURCE is a string containing image
data. If DATA-P is a symbol with a name on the format
`image/jpeg', that may be used as a hint to determine the image
type if we can't otherwise guess it."
(when (and (not data-p) (not (stringp source)))
(error "Invalid image file name `%s'" source))
(unless type
(setq type (if data-p
(or (image-type-from-data source)
(and image-use-external-converter
(progn
(require 'image-converter)
(image-convert-p source data-p))))
(or (image-type-from-file-header source)
(image-supported-file-p source)
(and image-use-external-converter
(progn
(require 'image-converter)
(image-convert-p source))))))
(unless type
(signal 'unknown-image-type '("Cannot determine image type"))))
(when (and (not (eq type 'image-convert))
(not (memq type (and (boundp 'image-types) image-types))))
(error "Invalid image type `%s'" type))
type)