VM

Fitting images to Emacs screen width

Bug #503865 reported by Uday Reddy
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
VM
Triaged
Wishlist
Unassigned

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" )))

Uday Reddy (reddyuday)
Changed in vm:
status: New → Triaged
importance: Undecided → Wishlist
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.