-(defun gnus-convert-image-to-gray-x-face (file depth)
- (let* ((mapfile (mm-make-temp-file (expand-file-name "gnus."
- mm-tmp-directory)))
- (levels (expt 2 depth))
- (step (/ 255 (1- levels)))
- color-alist bits bits-list mask pixel x-faces)
- (with-temp-file mapfile
- (insert "P3\n")
- (insert (format "%d 1\n" levels))
- (insert "255\n")
- (dotimes (i levels)
- (insert (format "%d %d %d\n"
- (* step i) (* step i) (* step i)))
- (push (cons (* step i) i) color-alist)))
- (when (file-exists-p file)
- (with-temp-buffer
- (insert (gnus-shell-command-to-string
- (format "giftopnm %s | ppmnorm | pnmscale -width 48 -height 48 | ppmquant -fs -map %s | ppmtopgm | pnmnoraw"
- (shell-quote-argument file)
- mapfile)))
- (goto-char (point-min))
- (forward-line 3)
- (while (setq pixel (ignore-errors (read (current-buffer))))
- (push (cdr (assq pixel color-alist)) bits-list))
- (setq bits-list (nreverse bits-list))
- (dotimes (bit-number depth)
- (setq mask (expt 2 bit-number))
- (with-temp-buffer
- (insert "P1\n48 48\n")
- (dolist (bits bits-list)
- (insert (if (zerop (logand bits mask)) "0 " "1 ")))
- (gnus-shell-command-on-region
- (point-min) (point-max)
- ;; the following is taken from xbmtoikon:
- "pbmtoicon | sed '/^[ ]*[*\\\\/]/d; s/[ ]//g; s/,$//' | tr , '\\012' | sed 's/^0x//; s/^/0x/' | pr -l1 -t -w22 -3 -s, | sed 's/,*$/,/' | compface")
- (push (buffer-string) x-faces))))
- (dotimes (i (length x-faces))
- (insert (if (zerop i) "X-Face:" (format "X-Face-%s:" i))
- (nth i x-faces))))
- (delete-file mapfile)))
+;;;###autoload
+(defun gnus-convert-png-to-face (file)
+ "Convert FILE to a Face.
+FILE should be a PNG file that's 48x48 and smaller than or equal to
+726 bytes."
+ (mm-with-unibyte-buffer
+ (insert-file-contents file)
+ (when (> (buffer-size) 726)
+ (error "The file is %d bytes long, which is too long"
+ (buffer-size)))
+ (gnus-face-encode)))