aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/image.el40
1 files changed, 30 insertions, 10 deletions
diff --git a/lisp/image.el b/lisp/image.el
index 1b07ee2491e..855dffad293 100644
--- a/lisp/image.el
+++ b/lisp/image.el
@@ -931,18 +931,18 @@ has no effect."
931If N is 3, then the image size will be increased by 30%. The 931If N is 3, then the image size will be increased by 30%. The
932default is 20%." 932default is 20%."
933 (interactive "P") 933 (interactive "P")
934 (image-change-size (if n 934 (image--change-size (if n
935 (1+ (/ n 10)) 935 (1+ (/ n 10))
936 1.2))) 936 1.2)))
937 937
938(defun image-decrease-size (n) 938(defun image-decrease-size (n)
939 "Decrease the image size by a factor of N. 939 "Decrease the image size by a factor of N.
940If N is 3, then the image size will be decreased by 30%. The 940If N is 3, then the image size will be decreased by 30%. The
941default is 20%." 941default is 20%."
942 (interactive "P") 942 (interactive "P")
943 (image-change-size (if n 943 (image--change-size (if n
944 (- 1 (/ n 10)) 944 (- 1 (/ n 10))
945 0.8))) 945 0.8)))
946 946
947(defun image--get-image () 947(defun image--get-image ()
948 (let ((image (or (get-text-property (point) 'display) 948 (let ((image (or (get-text-property (point) 'display)
@@ -964,10 +964,30 @@ default is 20%."
964 (plist-put (cdr image) :type 'imagemagick) 964 (plist-put (cdr image) :type 'imagemagick)
965 image)) 965 image))
966 966
967(defun image-change-size (factor) 967(defun image--change-size (factor)
968 (let ((image (image--get-imagemagick-and-warn))) 968 (let* ((image (image--get-imagemagick-and-warn))
969 (plist-put (cdr image) :scale 969 (new-image (image--image-without-parameters image))
970 (* (or (plist-get (cdr image) :scale) 1) factor)))) 970 (scale (image--current-scaling image new-image)))
971 (setcdr image (cdr new-image))
972 (plist-put (cdr image) :scale (* scale factor))))
973
974(defun image--image-without-parameters (image)
975 (cons (pop image)
976 (let ((new nil))
977 (while image
978 (let ((key (pop image))
979 (val (pop image)))
980 (unless (memq key '(:scale :width :height :max-width :max-height))
981 (setq new (nconc new (list key val))))))
982 new)))
983
984(defun image--current-scaling (image new-image)
985 ;; The image may be scaled due to many reasons (:scale, :max-width,
986 ;; etc), so find out what the current scaling is based on the
987 ;; original image size and the displayed size.
988 (let ((image-width (car (image-size new-image t)))
989 (display-width (car (image-size image t))))
990 (/ (float display-width) image-width)))
971 991
972(defun image-rotate () 992(defun image-rotate ()
973 "Rotate the image under point by 90 degrees clockwise." 993 "Rotate the image under point by 90 degrees clockwise."