- "minor mode for scaleing and rotation"
- nil "image-transform"
- image-transform-minor-mode-map)
-
-(defvar image-transform-resize nil
- "The image resize operation. See the command
- `image-transform-set-scale' for more information." )
-
-(defvar image-transform-rotation 0.0)
-
-
-(defun image-transform-properties (display)
- "Calculate the display properties for transformations; scaling
-and rotation. "
- (let*
- ((size (image-size display t))
- (height
- (cond
- ((and (numberp image-transform-resize) (eq 100 image-transform-resize))
- nil)
- ((numberp image-transform-resize)
- (* image-transform-resize (cdr size)))
- ((eq image-transform-resize 'fit-height)
- (- (nth 3 (window-inside-pixel-edges)) (nth 1 (window-inside-pixel-edges))))
- (t nil)))
- (width (if (eq image-transform-resize 'fit-width)
- (- (nth 2 (window-inside-pixel-edges)) (nth 0 (window-inside-pixel-edges))))))
-
- `(,@(if height (list :height height))
- ,@(if width (list :width width))
- ,@(if (not (equal 0.0 image-transform-rotation))
- (list :rotation image-transform-rotation))
+ "Minor mode for scaling and rotating images.
+This minor mode has no effect unless Emacs is compiled with
+ImageMagick support."
+ nil "image-transform" image-transform-minor-mode-map)
+
+(defvar image-transform-resize nil
+ "The image resize operation.
+Its value should be one of the following:
+ - nil, meaning no resizing.
+ - `fit-height', meaning to fit the image to the window height.
+ - `fit-width', meaning to fit the image to the window width.
+ - A number, which is a scale factor (the default size is 100).")
+
+(defvar image-transform-rotation 0.0
+ "Rotation angle for the image in the current Image mode buffer.")
+
+(defun image-transform-properties (spec)
+ "Return rescaling/rotation properties for image SPEC.
+These properties are determined by the Image mode variables
+`image-transform-resize' and `image-transform-rotation'. The
+return value is suitable for appending to an image spec.
+
+Recaling and rotation properties only take effect if Emacs is
+compiled with ImageMagick support."
+ (when (or image-transform-resize
+ (not (equal image-transform-rotation 0.0)))
+ ;; Note: `image-size' looks up and thus caches the untransformed
+ ;; image. There's no easy way to prevent that.
+ (let* ((size (image-size spec t))
+ (height
+ (cond
+ ((numberp image-transform-resize)
+ (unless (= image-transform-resize 100)
+ (* image-transform-resize (cdr size))))
+ ((eq image-transform-resize 'fit-height)
+ (- (nth 3 (window-inside-pixel-edges))
+ (nth 1 (window-inside-pixel-edges))))))
+ (width (if (eq image-transform-resize 'fit-width)
+ (- (nth 2 (window-inside-pixel-edges))
+ (nth 0 (window-inside-pixel-edges))))))