Function: image-display-size

image-display-size is a byte-compiled function defined in image-mode.el.gz.

Signature

(image-display-size SPEC &optional PIXELS FRAME)

Documentation

Wrapper around image-size, handling slice display properties.

Like image-size, the return value is (WIDTH . HEIGHT). WIDTH and HEIGHT are in canonical character units if PIXELS is nil, and in pixel units if PIXELS is non-nil.

If SPEC is an image display property, this function is equivalent to image-size. If SPEC represents an xwidget object, defer to xwidget-info. If SPEC is a list of properties containing image and slice properties, return the display size taking the slice property into account. If the list contains image but not slice, return the image-size of the specified image.

Source Code

;; Defined in /usr/src/emacs/lisp/image-mode.el.gz
(defun image-display-size (spec &optional pixels frame)
  "Wrapper around `image-size', handling slice display properties.
Like `image-size', the return value is (WIDTH . HEIGHT).
WIDTH and HEIGHT are in canonical character units if PIXELS is
nil, and in pixel units if PIXELS is non-nil.

If SPEC is an image display property, this function is equivalent to
`image-size'.  If SPEC represents an xwidget object, defer to `xwidget-info'.
If SPEC is a list of properties containing `image' and `slice' properties,
return the display size taking the slice property into account.  If the list
contains `image' but not `slice', return the `image-size' of the specified
image."
  (cond ((eq (car spec) 'xwidget)
         (let ((xwi (xwidget-info (xwidget-at (point-min)))))
           (cons (aref xwi 2) (aref xwi 3))))
        ((eq (car spec) 'image)
         (image-size spec pixels frame))
        (t (let ((image (assoc 'image spec))
                 (slice (assoc 'slice spec)))
             (cond ((and image slice)
                    (if pixels
                        (cons (nth 3 slice) (nth 4 slice))
                      (cons (/ (float (nth 3 slice)) (frame-char-width frame))
                            (/ (float (nth 4 slice))
                               (frame-char-height frame)))))
                   (image
                    (image-size image pixels frame))
                   (t
                    (error "Invalid image specification: %s" spec)))))))