[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: image-rotate: Accept angle as an argument
From: |
Tino Calancha |
Subject: |
Re: image-rotate: Accept angle as an argument |
Date: |
Mon, 5 Sep 2016 16:52:48 +0900 (JST) |
User-agent: |
Alpine 2.20 (DEB 67 2015-01-07) |
On Mon, 5 Sep 2016, Tino Calancha wrote:
Hello,
lisp/image.el defines 'image-increase-size' and 'image-decrease-size',
with an argument N. We might allow for an argument in 'image-rotate'
as well.
I would like also to modify 'image-increase-size' and
'image-decrease-size' as i did with 'image-rotate':
A prefix argument prompt user for the size factor. Then you can perform
arbitrary rotations and resize of an image using these commands as
follows:
;; FILE is the file name of an image file:
emacs -Q FILE:
1 r 15 RET ; rotate image 15 degrees
1 r -15 RET ; rotate image -15 degrees
1 + 50 RET ; increase image size 50%
1 - 40 RET ; decrease image size 40%
So the proposal is 2 patches:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
From aefda287d0d739c99f6e45f568a22b67f1eb19da Mon Sep 17 00:00:00 2001
From: Tino Calancha <address@hidden>
Date: Mon, 5 Sep 2016 16:26:03 +0900
Subject: [PATCH 1/2] image-rotate: Accept angle as an argument
* lisp/image.el (image-rotate):
Add argument ANGLE, the angle in degrees for the rotation.
Add optional argument _ARG; in interactive calls, a non-nil
value prompt for ANGLE.
---
lisp/image.el | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/lisp/image.el b/lisp/image.el
index e1f52de..cad8332 100644
--- a/lisp/image.el
+++ b/lisp/image.el
@@ -1008,12 +1008,21 @@ image--current-scaling
(display-width (car (image-size image t))))
(/ (float display-width) image-width)))
-(defun image-rotate ()
- "Rotate the image under point by 90 degrees clockwise."
- (interactive)
+(defun image-rotate (angle &optional _arg)
+ "Rotate the image under point by ANGLE degrees clockwise.
+If ANGLE is a negative number, then rotate counterclockwise.
+When called interactively with a prefix argument, prompt for ANGLE."
+ (interactive
+ (let* ((ask current-prefix-arg)
+ (default 90)
+ (prompt "Rotate image by ANGLE degrees: ")
+ (rotation (if ask
+ (read-number prompt default)
+ default)))
+ (list rotation ask)))
(let ((image (image--get-imagemagick-and-warn)))
(plist-put (cdr image) :rotation
- (float (mod (+ (or (plist-get (cdr image) :rotation) 0)
90)
+ (float (mod (+ (or (plist-get (cdr image) :rotation) 0)
angle)
;; We don't want to exceed 360 degrees
;; rotation, because it's not seen as valid
;; in exif data.
--
2.9.3
From 7428267a2723315e9a8df3f7a687aeb66513dde4 Mon Sep 17 00:00:00 2001
From: Tino Calancha <address@hidden>
Date: Mon, 5 Sep 2016 16:29:56 +0900
Subject: [PATCH 2/2] image-increase-size: Prompt for size factor in
interactive calls
* lisp/image.el (image-increase-size, image-decrease-size):
Add optional argument _ARG; in interactive calls, a non-nil
value prompt for the size factor.
---
lisp/image.el | 43 ++++++++++++++++++++++++++++---------------
1 file changed, 28 insertions(+), 15 deletions(-)
diff --git a/lisp/image.el b/lisp/image.el
index cad8332..1bfa042 100644
--- a/lisp/image.el
+++ b/lisp/image.el
@@ -951,23 +951,36 @@ imagemagick-enabled-types
(imagemagick-register-types)
-(defun image-increase-size (n)
- "Increase the image size by a factor of N.
+(defun image-increase-size (n &optional _arg)
+ "Increase the image size.
If N is 3, then the image size will be increased by 30%. The
-default is 20%."
- (interactive "P")
- (image--change-size (if n
- (1+ (/ n 10.0))
- 1.2)))
-
-(defun image-decrease-size (n)
- "Decrease the image size by a factor of N.
+default is 20%.
+When called interactively with a prefix argument, prompt for N."
+ (interactive
+ (let* ((ask current-prefix-arg)
+ (default 20)
+ (num (if ask
+ (read-number "Increase image size by X %: " default)
+ default)))
+ (list (/ num 10.0) ask)))
+ (image--change-size (1+ (/ n 10.0))))
+
+(defun image-decrease-size (n &optional _arg)
+ "Decrease the image size.
If N is 3, then the image size will be decreased by 30%. The
-default is 20%."
- (interactive "P")
- (image--change-size (if n
- (- 1 (/ n 10.0))
- 0.8)))
+default is 20%.
+When called interactively with a prefix argument, prompt for N."
+ (interactive
+ (let* ((ask current-prefix-arg)
+ (default 20)
+ (num (if ask
+ (read-number "Decrease image size by X %: " default)
+ default)))
+ (list (/ num 10.0) ask)))
+ (let ((decrease (/ n 10.0)))
+ (image--change-size (if (< decrease 1)
+ (- 1 decrease)
+ 0))))
(defun image--get-image ()
(let ((image (get-text-property (point) 'display)))
--
2.9.3
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
In GNU Emacs 25.1.50.1 (x86_64-pc-linux-gnu, GTK+ Version 3.20.9)
of 2016-09-05
Repository revision: 62e4dc4660cb3b29cfffcad0639e51c7f382ced8