1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-04-27 08:43:40 -07:00

New command image-transform-set-percent

* lisp/image-mode.el (image-transform-set-percent): New command.
(image-mode-map): Bind above new command to "s p".
* doc/emacs/files.texi (Image Mode): Document it.
This commit is contained in:
Stefan Kangas 2021-10-28 03:36:28 +02:00 committed by Stefan Kangas
parent 9f8e16d828
commit 0dc9c9a68f
3 changed files with 24 additions and 6 deletions

View file

@ -2273,12 +2273,14 @@ behavior by using the options @code{image-auto-resize} and
@findex image-transform-set-scale
@findex image-transform-reset
To resize the image manually you can use the command
@code{image-transform-fit-to-window} bound to @kbd{s w}
that fits the image to both the window height and width.
To scale the image specifying a scale factor, use the command
@code{image-transform-set-scale} bound to @kbd{s s}.
To reset all transformations to the initial state, use
@code{image-transform-reset} bound to @kbd{s 0}.
@code{image-transform-fit-to-window} bound to @kbd{s w} that fits the
image to both the window height and width. To scale the image to a
percentage of its original size, use the command
@code{image-transform-set-percent} bound to @kbd{s p}. To scale
the image specifying a scale factor, use the command
@code{image-transform-set-scale} bound to @kbd{s s}. To reset all
transformations to the initial state, use @code{image-transform-reset}
bound to @kbd{s 0}.
@findex image-next-file
@findex image-previous-file

View file

@ -1863,6 +1863,11 @@ this message for SVG and XPM.
*** New commands: 'image-flip-horizontally' and 'image-flip-vertically'.
These commands horizontally and vertically flip the image under point.
+++
*** New command 'image-transform-set-percent'.
It allows setting the image size to a percentage of its original size,
and is bound to "s p" in Image mode.
** Images
+++

View file

@ -494,6 +494,7 @@ image as text, when opening such images in `image-mode'."
"s h" #'image-transform-fit-to-height
"s i" #'image-transform-fit-to-width
"s b" #'image-transform-fit-both
"s p" #'image-transform-set-percent
"s s" #'image-transform-set-scale
"s r" #'image-transform-set-rotation
"s m" #'image-transform-set-smoothing
@ -1530,6 +1531,16 @@ return value is suitable for appending to an image spec."
(list :transform-smoothing
(string= image--transform-smoothing "smooth")))))))
(defun image-transform-set-percent (scale)
"Prompt for a percentage, and resize the current image to that size.
The percentage is in relation to the original size of the image."
(interactive (list (read-number "Scale (% of original): " 100
'read-number-history)))
(unless (cl-plusp scale)
(error "Not a positive number: %s" scale))
(setq image-transform-resize (/ scale 100.0))
(image-toggle-display-image))
(defun image-transform-set-scale (scale)
"Prompt for a number, and resize the current image by that amount."
(interactive "nScale: ")