vm team mailing list archive
-
vm team
-
Mailing list archive
-
Message #00392
[Bug 503865] [NEW] Fitting images to Emacs screen width
Public bug reported:
Blueman (vm.info, 2010-01-04)
On the rare occassions that I use a graphical emacs terminal, I have
noted that images don't seem to "fit to screen". Even worse, while you
can scroll vertically, there doesn't seem to be any horizontal
scrollbar.
Of course you can use the vm-menu-fsfemacs-image-menu to reduce the size
by 2X but that is pretty course adjustment.
So, I long ago wrote a very simple routine that fits the image to screen
and I also added the routine to the images menu.
However, I'm not sure where is the best place to add this routine so
that any oversized images automatically are resized to fit at least
within the screen width (and perhaps also within the height too).
Anyway, in case anyone else is interested, here is the manual routine I
use:
;; Stretch/Shrink mime image to fit exactly in frame width.
;; The shrink functionality is particularly helpful since images displayed
;; by emacs look wacked when they extend past a line width
(defun vm-mime-fitwidth-image (extent)
"Stretch/Shrink mime image to fit exactly in frame width (JJK)."
(let* ((layout (vm-extent-property extent 'vm-mime-layout))
(blob (get (vm-mm-layout-cache layout)
'vm-mime-display-internal-image-xxxx))
dims factor)
;; Emacs 19 uses a different layout cache than XEmacs or Emacs 21+.
;; The cache blob is a list in that case.
(if (consp blob) (setq blob (car blob)))
(setq dims (vm-get-image-dimensions blob))
(setq factor (/ (float (* (1- (frame-width)) (frame-char-width))) (car dims)))
(vm-mime-frob-image-xxxx extent
"-scale"
(concat (int-to-string (* factor (car dims)))
"x"
(int-to-string (* factor (nth 1 dims)))))))
;; Functionality to add above function to: vm-menu-fsfemacs-image-menu
;; Also add functions to: vm-menu-fsfemacs-attachment-menu
(add-hook 'vm-menu-setup-hook
(lambda ()
(require 'easymenu)
; Add to image menu
(easy-menu-add-item vm-menu-fsfemacs-image-menu
nil
["Fit to width"
(vm-mime-run-display-function-at-point 'vm-mime-fitwidth-image)
(stringp vm-imagemagick-convert-program)]
"4x Larger" )))
** Affects: vm
Importance: Wishlist
Status: Triaged
** Changed in: vm
Status: New => Triaged
** Changed in: vm
Importance: Undecided => Wishlist
--
Fitting images to Emacs screen width
https://bugs.launchpad.net/bugs/503865
You received this bug notification because you are a member of VM
development team, which is the registrant for VM.
Status in VM (View Mail) for Emacs: Triaged
Bug description:
Blueman (vm.info, 2010-01-04)
On the rare occassions that I use a graphical emacs terminal, I have
noted that images don't seem to "fit to screen". Even worse, while you
can scroll vertically, there doesn't seem to be any horizontal
scrollbar.
Of course you can use the vm-menu-fsfemacs-image-menu to reduce the size
by 2X but that is pretty course adjustment.
So, I long ago wrote a very simple routine that fits the image to screen
and I also added the routine to the images menu.
However, I'm not sure where is the best place to add this routine so
that any oversized images automatically are resized to fit at least
within the screen width (and perhaps also within the height too).
Anyway, in case anyone else is interested, here is the manual routine I
use:
;; Stretch/Shrink mime image to fit exactly in frame width.
;; The shrink functionality is particularly helpful since images displayed
;; by emacs look wacked when they extend past a line width
(defun vm-mime-fitwidth-image (extent)
"Stretch/Shrink mime image to fit exactly in frame width (JJK)."
(let* ((layout (vm-extent-property extent 'vm-mime-layout))
(blob (get (vm-mm-layout-cache layout)
'vm-mime-display-internal-image-xxxx))
dims factor)
;; Emacs 19 uses a different layout cache than XEmacs or Emacs 21+.
;; The cache blob is a list in that case.
(if (consp blob) (setq blob (car blob)))
(setq dims (vm-get-image-dimensions blob))
(setq factor (/ (float (* (1- (frame-width)) (frame-char-width))) (car dims)))
(vm-mime-frob-image-xxxx extent
"-scale"
(concat (int-to-string (* factor (car dims)))
"x"
(int-to-string (* factor (nth 1 dims)))))))
;; Functionality to add above function to: vm-menu-fsfemacs-image-menu
;; Also add functions to: vm-menu-fsfemacs-attachment-menu
(add-hook 'vm-menu-setup-hook
(lambda ()
(require 'easymenu)
; Add to image menu
(easy-menu-add-item vm-menu-fsfemacs-image-menu
nil
["Fit to width"
(vm-mime-run-display-function-at-point 'vm-mime-fitwidth-image)
(stringp vm-imagemagick-convert-program)]
"4x Larger" )))
Follow ups
References