+(defun image--set-speed (speed &optional multiply)
+ "Set speed of an animated image to SPEED.
+If MULTIPLY is non-nil, treat SPEED as a multiplication factor.
+If SPEED is `reset', reset the magnitude of the speed to 1."
+ (let ((image (image-get-display-property)))
+ (cond
+ ((null image)
+ (error "No image is present"))
+ ((null image-multi-frame)
+ (message "No image animation."))
+ (t
+ (if (eq speed 'reset)
+ (setq speed (if (< (image-animate-get-speed image) 0)
+ -1 1)
+ multiply nil))
+ (image-animate-set-speed image speed multiply)
+ ;; FIXME Hack to refresh an active image.
+ (when (image-animate-timer image)
+ (image-toggle-animation)
+ (image-toggle-animation))
+ (message "Image speed is now %s" (image-animate-get-speed image))))))
+
+(defun image-increase-speed ()
+ "Increase the speed of current animated image by a factor of 2."
+ (interactive)
+ (image--set-speed 2 t))
+
+(defun image-decrease-speed ()
+ "Decrease the speed of current animated image by a factor of 2."
+ (interactive)
+ (image--set-speed 0.5 t))
+
+(defun image-reverse-speed ()
+ "Reverse the animation of the current image."
+ (interactive)
+ (image--set-speed -1 t))
+
+(defun image-reset-speed ()
+ "Reset the animation speed of the current image."
+ (interactive)
+ (image--set-speed 'reset))
+