From: Lars Magne Ingebrigtsen Date: Wed, 1 Sep 2010 15:05:53 +0000 (+0200) Subject: Rescale images in article buffers for Emacs versions that support this. X-Git-Url: http://cgit.sxemacs.org/?a=commitdiff_plain;h=a4578aa72634bbbc9e8c06117265eb6accca4161;p=gnus Rescale images in article buffers for Emacs versions that support this. This is currently only Emacs 24 compiled with imagemagick support. --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 456781f74..14d60bb9d 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,6 +1,9 @@ 2010-09-01 Lars Magne Ingebrigtsen * gnus-html.el (gnus-html-wash-tags): Delete the IMG_ALT region. + (gnus-max-image-proportion): New variable. + (gnus-html-rescale-image): New function. + (gnus-html-put-image): Rescale images. 2010-09-01 Katsumi Yamaoka diff --git a/lisp/gnus-html.el b/lisp/gnus-html.el index 888b29881..ea5137b5d 100644 --- a/lisp/gnus-html.el +++ b/lisp/gnus-html.el @@ -56,6 +56,16 @@ :group 'gnus-art :type 'regexp) +(defcustom gnus-max-image-proportion 0.7 + "How big pictures displayed are in relation to the window they're in. +A value of 0.7 means that they are allowed to take up 70% of the +width and height of the window. If they are larger than this, +and Emacs supports it, then the images will be rescaled down to +fit these criteria." + :version "24.1" + :group 'gnus-art + :type 'float) + ;;;###autoload (defun gnus-article-html (handle) (let ((article-buffer (current-buffer))) @@ -216,13 +226,33 @@ (= (car (image-size image t)) 30) (= (cdr (image-size image t)) 30)))) (progn - (gnus-put-image image) + (gnus-put-image (gnus-html-rescale-image image)) t) (when (fboundp 'find-image) (gnus-put-image (find-image '((:type xpm :file "lock-broken.xpm"))))) nil))))) +(defun gnus-html-rescale-image (image) + (if (not (fboundp 'imagemagick-types)) + image + (let* ((width (car (image-size image t))) + (height (cdr (image-size image t))) + (edges (window-pixel-edges)) + (window-width (truncate (* gnus-max-image-proportion + (- (nth 2 edges) (nth 0 edges))))) + (window-height (truncate (* gnus-max-image-proportion + (- (nth 3 edges) (nth 1 edges))))) + scaled-image) + (when (> width window-width) + (setq window-height (truncate (* window-height + (/ (* 1.0 window-width) width))))) + (if (> height window-height) + (or (create-image file 'imagemagick nil + :height window-height) + image) + image)))) + (defun gnus-html-prune-cache () (let ((total-size 0) files) diff --git a/texi/ChangeLog b/texi/ChangeLog index 3085dcd20..e202b5928 100644 --- a/texi/ChangeLog +++ b/texi/ChangeLog @@ -1,3 +1,7 @@ +2010-09-01 Lars Magne Ingebrigtsen + + * gnus.texi (HTML): Document gnus-max-image-proportion. + 2010-08-31 Lars Magne Ingebrigtsen * gnus.texi (HTML): Document gnus-blocked-images. diff --git a/texi/gnus.texi b/texi/gnus.texi index 25b06288b..9ebfd1be5 100644 --- a/texi/gnus.texi +++ b/texi/gnus.texi @@ -12515,6 +12515,14 @@ directory, the oldest files will be deleted. The default is 500MB. @vindex gnus-html-frame-width The width to use when rendering HTML. The default is 70. +@item gnus-max-image-proportion +@vindex gnus-max-image-proportion +How big pictures displayed are in relation to the window they're in. +A value of 0.7 (the default) means that they are allowed to take up +70% of the width and height of the window. If they are larger than +this, and Emacs supports it, then the images will be rescaled down to +fit these criteria. + @end table To use this, make sure that you have @code{w3m} and @code{curl}