Function: image-transform-width

image-transform-width is a byte-compiled function defined in image-mode.el.gz.

Signature

(image-transform-width WIDTH HEIGHT)

Documentation

Return the bounding box width of a rotated WIDTH x HEIGHT rectangle.

The rotation angle is the value of image-transform-rotation in degrees.

Source Code

;; Defined in /usr/src/emacs/lisp/image-mode.el.gz
;; Not yet implemented.
;; (defvar image-transform-minor-mode-map
;;   (let ((map (make-sparse-keymap)))
;;     ;; (define-key map  [(control ?+)] 'image-scale-in)
;;     ;; (define-key map  [(control ?-)] 'image-scale-out)
;;     ;; (define-key map  [(control ?=)] 'image-scale-none)
;;     ;; (define-key map "c f h" 'image-scale-fit-height)
;;     ;; (define-key map "c ]" 'image-rotate-right)
;;     map)
;;   "Minor mode keymap `image-transform-mode'.")
;;
;; (define-minor-mode image-transform-mode
;;   "Minor mode for scaling and rotating images.
;; With a prefix argument ARG, enable the mode if ARG is positive,
;; and disable it otherwise.  If called from Lisp, enable the mode
;; if ARG is omitted or nil.  This minor mode requires Emacs to have
;; been compiled with ImageMagick support."
;;   nil "image-transform" image-transform-minor-mode-map)


(defsubst image-transform-width (width height)
  "Return the bounding box width of a rotated WIDTH x HEIGHT rectangle.
The rotation angle is the value of `image-transform-rotation' in degrees."
  (let ((angle (degrees-to-radians image-transform-rotation)))
    ;; Assume, w.l.o.g., that the vertices of the rectangle have the
    ;; coordinates (+-w/2, +-h/2) and that (0, 0) is the center of the
    ;; rotation by the angle A.  The projections onto the first axis
    ;; of the vertices of the rotated rectangle are +- (w/2) cos A +-
    ;; (h/2) sin A, and the difference between the largest and the
    ;; smallest of the four values is the expression below.
    (+ (* width (abs (cos angle))) (* height (abs (sin angle))))))