Mercurial > emacs
diff lisp/image.el @ 90386:2ecafc6d5db7
Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-58
Merge from emacs--devo--0
Patches applied:
* emacs--devo--0 (patch 239-258)
- Update from CVS
- (Ffield_beginning, find_field): Undo change of 2006-04-23.
- Rcirc patch from Ryan Yeske
- Merge from gnus--rel--5.10
- Clean up lisp/gnus/ChangeLog a bit
* gnus--rel--5.10 (patch 91-98)
- Merge from emacs--devo--0
- Update from CVS
author | Miles Bader <miles@gnu.org> |
---|---|
date | Tue, 02 May 2006 05:51:52 +0000 |
parents | e6bf73e43cf4 de6c9508749d |
children | bc10a33dd40b |
line wrap: on
line diff
--- a/lisp/image.el Fri Apr 21 05:39:14 2006 +0000 +++ b/lisp/image.el Tue May 02 05:51:52 2006 +0000 @@ -280,6 +280,35 @@ ;;;###autoload +(defun image-type (file-or-data &optional type data-p) + "Determine and return image type. +FILE-OR-DATA 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 FILE-OR-DATA is a file name, +use its file extension as image type. +Optional DATA-P non-nil means FILE-OR-DATA is a string containing image data." + (when (and (not data-p) (not (stringp file-or-data))) + (error "Invalid image file name `%s'" file-or-data)) + (cond ((null data-p) + ;; FILE-OR-DATA is a file name. + (unless (or type + (setq type (image-type-from-file-header file-or-data))) + (let ((extension (file-name-extension file-or-data))) + (unless extension + (error "Cannot determine image type")) + (setq type (intern extension))))) + (t + ;; FILE-OR-DATA contains image data. + (unless type + (setq type (image-type-from-data file-or-data))))) + (unless type + (error "Cannot determine image type")) + (unless (symbolp type) + (error "Invalid image type `%s'" type)) + type) + +;;;###autoload (defun image-type-available-p (type) "Return non-nil if image type TYPE is available. Image types are symbols like `xbm' or `jpeg'." @@ -301,24 +330,7 @@ Value is the image created, or nil if images of type TYPE are not supported. Images should not be larger than specified by `max-image-size'." - (when (and (not data-p) (not (stringp file-or-data))) - (error "Invalid image file name `%s'" file-or-data)) - (cond ((null data-p) - ;; FILE-OR-DATA is a file name. - (unless (or type - (setq type (image-type-from-file-header file-or-data))) - (let ((extension (file-name-extension file-or-data))) - (unless extension - (error "Cannot determine image type")) - (setq type (intern extension))))) - (t - ;; FILE-OR-DATA contains image data. - (unless type - (setq type (image-type-from-data file-or-data))))) - (unless type - (error "Cannot determine image type")) - (unless (symbolp type) - (error "Invalid image type `%s'" type)) + (setq type (image-type file-or-data type data-p)) (when (image-type-available-p type) (append (list 'image :type type (if data-p :data :file) file-or-data) props)))