diff options
| author | Kim F. Storm | 2006-04-21 20:56:06 +0000 |
|---|---|---|
| committer | Kim F. Storm | 2006-04-21 20:56:06 +0000 |
| commit | e796837385175997fd30d907d0cd7fac06617dcd (patch) | |
| tree | 450730d88e518ca6f28b8f32031dace47b9f51da | |
| parent | 15855f8f789cbe98f2df394904350bfaec71bd53 (diff) | |
| download | emacs-e796837385175997fd30d907d0cd7fac06617dcd.tar.gz emacs-e796837385175997fd30d907d0cd7fac06617dcd.zip | |
(image-type): New defun split out of create-image.
(create-image): Use it.
| -rw-r--r-- | lisp/image.el | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/lisp/image.el b/lisp/image.el index 2212b0fb471..b388396ded7 100644 --- a/lisp/image.el +++ b/lisp/image.el | |||
| @@ -280,27 +280,14 @@ be determined." | |||
| 280 | 280 | ||
| 281 | 281 | ||
| 282 | ;;;###autoload | 282 | ;;;###autoload |
| 283 | (defun image-type-available-p (type) | 283 | (defun image-type (file-or-data &optional type data-p) |
| 284 | "Return non-nil if image type TYPE is available. | 284 | "Determine and return image type. |
| 285 | Image types are symbols like `xbm' or `jpeg'." | ||
| 286 | (and (fboundp 'init-image-library) | ||
| 287 | (init-image-library type image-library-alist))) | ||
| 288 | |||
| 289 | |||
| 290 | ;;;###autoload | ||
| 291 | (defun create-image (file-or-data &optional type data-p &rest props) | ||
| 292 | "Create an image. | ||
| 293 | FILE-OR-DATA is an image file name or image data. | 285 | FILE-OR-DATA is an image file name or image data. |
| 294 | Optional TYPE is a symbol describing the image type. If TYPE is omitted | 286 | Optional TYPE is a symbol describing the image type. If TYPE is omitted |
| 295 | or nil, try to determine the image type from its first few bytes | 287 | or nil, try to determine the image type from its first few bytes |
| 296 | of image data. If that doesn't work, and FILE-OR-DATA is a file name, | 288 | of image data. If that doesn't work, and FILE-OR-DATA is a file name, |
| 297 | use its file extension as image type. | 289 | use its file extension as image type. |
| 298 | Optional DATA-P non-nil means FILE-OR-DATA is a string containing image data. | 290 | Optional DATA-P non-nil means FILE-OR-DATA is a string containing image data." |
| 299 | Optional PROPS are additional image attributes to assign to the image, | ||
| 300 | like, e.g. `:mask MASK'. | ||
| 301 | Value is the image created, or nil if images of type TYPE are not supported. | ||
| 302 | |||
| 303 | Images should not be larger than specified by `max-image-size'." | ||
| 304 | (when (and (not data-p) (not (stringp file-or-data))) | 291 | (when (and (not data-p) (not (stringp file-or-data))) |
| 305 | (error "Invalid image file name `%s'" file-or-data)) | 292 | (error "Invalid image file name `%s'" file-or-data)) |
| 306 | (cond ((null data-p) | 293 | (cond ((null data-p) |
| @@ -319,6 +306,31 @@ Images should not be larger than specified by `max-image-size'." | |||
| 319 | (error "Cannot determine image type")) | 306 | (error "Cannot determine image type")) |
| 320 | (unless (symbolp type) | 307 | (unless (symbolp type) |
| 321 | (error "Invalid image type `%s'" type)) | 308 | (error "Invalid image type `%s'" type)) |
| 309 | type) | ||
| 310 | |||
| 311 | ;;;###autoload | ||
| 312 | (defun image-type-available-p (type) | ||
| 313 | "Return non-nil if image type TYPE is available. | ||
| 314 | Image types are symbols like `xbm' or `jpeg'." | ||
| 315 | (and (fboundp 'init-image-library) | ||
| 316 | (init-image-library type image-library-alist))) | ||
| 317 | |||
| 318 | |||
| 319 | ;;;###autoload | ||
| 320 | (defun create-image (file-or-data &optional type data-p &rest props) | ||
| 321 | "Create an image. | ||
| 322 | FILE-OR-DATA is an image file name or image data. | ||
| 323 | Optional TYPE is a symbol describing the image type. If TYPE is omitted | ||
| 324 | or nil, try to determine the image type from its first few bytes | ||
| 325 | of image data. If that doesn't work, and FILE-OR-DATA is a file name, | ||
| 326 | use its file extension as image type. | ||
| 327 | Optional DATA-P non-nil means FILE-OR-DATA is a string containing image data. | ||
| 328 | Optional PROPS are additional image attributes to assign to the image, | ||
| 329 | like, e.g. `:mask MASK'. | ||
| 330 | Value is the image created, or nil if images of type TYPE are not supported. | ||
| 331 | |||
| 332 | Images should not be larger than specified by `max-image-size'." | ||
| 333 | (setq type (image-type file-or-data type data-p)) | ||
| 322 | (when (image-type-available-p type) | 334 | (when (image-type-available-p type) |
| 323 | (append (list 'image :type type (if data-p :data :file) file-or-data) | 335 | (append (list 'image :type type (if data-p :data :file) file-or-data) |
| 324 | props))) | 336 | props))) |