+ :type '(choice (const :tag "giftopnm, netpbm (GIF input only)"
+ "giftopnm %s | ppmnorm | pnmscale -width 48 -height 48 | ppmtopgm | pgmtopbm | pbmtoxbm | compface")
+ (const :tag "convert"
+ "convert -scale 48x48! %s xbm:- | xbm2xface.pl")
+ (string)))
+
+(defcustom gnus-convert-image-to-face-command
+ "convert -scale 48x48! %s -colors %d png:-"
+ "Command for converting an image to a Face.
+
+The command must take an image filename (first format argument
+\"%s\") and the number of colors (second format argument: \"%d\")
+as input. The output must be the Face header data on stdout in
+PNG format."
+ :version "22.1"
+ :group 'gnus-fun
+ :type '(choice (const :tag "djpeg, netpbm (JPG input only)"
+ "djpeg %s | ppmnorm | pnmscale -width 48 -height 48 | ppmquant %d | pnmtopng")
+ (const :tag "convert"
+ "convert -scale 48x48! %s -colors %d png:-")
+ (string)))
+
+(defun gnus-shell-command-to-string (command)
+ "Like `shell-command-to-string' except not mingling ERROR."
+ (with-output-to-string
+ (call-process shell-file-name nil (list standard-output nil)
+ nil shell-command-switch command)))
+
+;;;###autoload
+(defun gnus--random-face-with-type (dir ext omit fun)
+ "Return file from DIR with extension EXT, omitting matches of OMIT, processed by FUN."
+ (when (file-exists-p dir)
+ (let* ((files
+ (remove nil (mapcar
+ (lambda (f) (unless (string-match (or omit "^$") f) f))
+ (directory-files dir t ext))))
+ (file (nth (random (length files)) files)))
+ (when file
+ (funcall fun file)))))
+
+;;;###autoload
+(autoload 'message-goto-eoh "message" nil t)
+(autoload 'message-insert-header "message" nil t)
+
+(defun gnus--insert-random-face-with-type (fun type)
+ "Get a random face using FUN and insert it as a header TYPE.
+
+For instance, to insert an X-Face use `gnus-random-x-face' as FUN
+ and \"X-Face\" as TYPE."
+ (let ((data (funcall fun)))
+ (save-excursion
+ (if data
+ (progn (message-goto-eoh)
+ (insert type ": " data "\n"))
+ (message
+ "No face returned by the function %s." (symbol-name fun))))))
+
+