- (let* ((image (ignore-errors
- (gnus-create-image file)))
- (size (and image
- (if (featurep 'xemacs)
- (cons (glyph-width image) (glyph-height image))
- (image-size image t)))))
- (save-excursion
- (goto-char point)
- (if (and image
- ;; Kludge to avoid displaying 30x30 gif images, which
- ;; seems to be a signal of a broken image.
- (not (and (if (featurep 'xemacs)
- (glyphp image)
- (listp image))
- (eq (if (featurep 'xemacs)
- (let ((data (cdadar (specifier-spec-list
- (glyph-image image)))))
- (and (vectorp data)
- (aref data 0)))
- (plist-get (cdr image) :type))
- 'gif)
- (= (car size) 30)
- (= (cdr size) 30))))
- (let ((start (point)))
- (setq image (gnus-html-rescale-image image file size))
- (gnus-put-image image
- (gnus-string-or string "*")
- 'external)
- (let ((overlay (gnus-make-overlay start (point))))
- (gnus-overlay-put overlay 'local-map
- gnus-html-displayed-image-map)
- (gnus-put-text-property start (point) 'gnus-alt-text alt-text)
- (when url
- (gnus-put-text-property start (point) 'gnus-image url)))
- (gnus-add-image 'external image)
- t)
- (insert string)
- (when (fboundp 'find-image)
- (setq image (find-image '((:type xpm :file "lock-broken.xpm"))))
- (gnus-put-image image
- (gnus-string-or string "*")
- 'internal)
- (gnus-add-image 'internal image))
- nil)))))
-
-(defun gnus-html-rescale-image (image file size)
- (if (or (not (fboundp 'imagemagick-types))
- (not (get-buffer-window (current-buffer))))
- image
- (let* ((width (car size))
- (height (cdr size))
- (edges (window-pixel-edges (get-buffer-window (current-buffer))))
- (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 (> height window-height)
- (setq image (or (create-image file 'imagemagick nil
- :height window-height)
- image))
- (setq size (image-size image t)))
- (when (> (car size) window-width)
- (setq image (or
- (create-image file 'imagemagick nil
- :width window-width)
- image)))
- image)))
-
-(defun gnus-html-prune-cache ()
- (let ((total-size 0)
- files)
- (dolist (file (directory-files gnus-html-cache-directory t nil t))
- (let ((attributes (file-attributes file)))
- (unless (nth 0 attributes)
- (incf total-size (nth 7 attributes))
- (push (list (time-to-seconds (nth 5 attributes))
- (nth 7 attributes) file)
- files))))
- (when (> total-size gnus-html-cache-size)
- (setq files (sort files (lambda (f1 f2)
- (< (car f1) (car f2)))))
- (dolist (file files)
- (when (> total-size gnus-html-cache-size)
- (decf total-size (cadr file))
- (delete-file (nth 2 file)))))))
+ (let* ((start (text-property-any (point-min) (point-max)
+ 'gnus-image-url url))
+ (end (when start
+ (next-single-property-change start 'gnus-image-url))))
+ ;; Image found?
+ (when start
+ (let* ((image
+ (ignore-errors
+ (gnus-create-image data nil t)))
+ (size (and image
+ (if (featurep 'xemacs)
+ (cons (glyph-width image) (glyph-height image))
+ (image-size image t)))))
+ (save-excursion
+ (goto-char start)
+ (let ((alt-text (or alt-text
+ (buffer-substring-no-properties start end))))
+ (if (and image
+ ;; Kludge to avoid displaying 30x30 gif images, which
+ ;; seems to be a signal of a broken image.
+ (not (and (if (featurep 'xemacs)
+ (glyphp image)
+ (listp image))
+ (eq (if (featurep 'xemacs)
+ (let ((d (cdadar
+ (specifier-spec-list
+ (glyph-image image)))))
+ (and (vectorp d)
+ (aref d 0)))
+ (plist-get (cdr image) :type))
+ 'gif)
+ (= (car size) 30)
+ (= (cdr size) 30))))
+ ;; Good image, add it!
+ (let ((image (gnus-rescale-image
+ image
+ (let ((edges (gnus-window-inside-pixel-edges
+ (get-buffer-window (current-buffer)))))
+ ;; (width . height)
+ (cons
+ ;; Aimed width
+ (truncate
+ (* gnus-max-image-proportion
+ (- (nth 2 edges) (nth 0 edges))))
+ ;; Aimed height
+ (truncate (* gnus-max-image-proportion
+ (- (nth 3 edges) (nth 1 edges)))))))))
+ (delete-region start end)
+ (gnus-put-image image alt-text 'external)
+ (gnus-put-text-property start (point) 'help-echo alt-text)
+ (gnus-overlay-put
+ (gnus-make-overlay start (point)) 'local-map
+ gnus-html-displayed-image-map)
+ (gnus-put-text-property start (point)
+ 'gnus-alt-text alt-text)
+ (when url
+ (gnus-put-text-property start (point)
+ 'gnus-image-url url))
+ (gnus-add-image 'external image)
+ t)
+ ;; Bad image, try to show something else
+ (when (fboundp 'find-image)
+ (delete-region start end)
+ (setq image (find-image
+ '((:type xpm :file "lock-broken.xpm"))))
+ (gnus-put-image image alt-text 'internal)
+ (gnus-add-image 'internal image))
+ nil))))))))