Mercurial > emacs
comparison lisp/image.el @ 70170:de6c9508749d
(image-type): New defun split out of create-image.
(create-image): Use it.
author | Kim F. Storm <storm@cua.dk> |
---|---|
date | Fri, 21 Apr 2006 20:56:06 +0000 |
parents | dd7f85a6af09 |
children | 3fb128bfa8b4 2ecafc6d5db7 |
comparison
equal
deleted
inserted
replaced
70169:10be49d855c4 | 70170:de6c9508749d |
---|---|
278 (setq types (cdr types)))) | 278 (setq types (cdr types)))) |
279 type)) | 279 type)) |
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) |
307 ;; FILE-OR-DATA is a file name. | 294 ;; FILE-OR-DATA is a file name. |
308 (unless (or type | 295 (unless (or type |
317 (setq type (image-type-from-data file-or-data))))) | 304 (setq type (image-type-from-data file-or-data))))) |
318 (unless type | 305 (unless type |
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))) |
325 | 337 |
326 | 338 |