18.19 Viewing Image Files
Visiting image files automatically selects Image mode. In this major mode, you can type C-c C-c
(image-toggle-display
) to toggle between displaying the file as an image in the Emacs buffer, and displaying its underlying text (or raw byte) representation. Additionally you can type C-c C-x
(image-toggle-hex-display
) to toggle between displaying the file as an image in the Emacs buffer, and displaying it in hex representation. Displaying the file as an image works only if Emacs is compiled with support for displaying such images.
If the displayed image is wider or taller than the window in which it is displayed, the usual point motion keys (C-f
, C-p
, and so forth) cause different parts of the image to be displayed. However, by default images are resized automatically to fit the window, so this is only necessary if you customize the default behavior by using the options image-auto-resize
and image-auto-resize-on-window-resize
.
To resize the image manually you can use the command image-transform-fit-both
bound to s b
that fits the image to both the window height and width. To scale the image specifying a scale factor, use the command image-transform-set-scale
bound to s s
. To reset all transformations to the initial state, use image-transform-reset
bound to s 0
.
You can press n
(image-next-file
) and p
(image-previous-file
) to visit the next image file and the previous image file in the same directory, respectively.
When looking through images, it’s sometimes convenient to be able to mark the files for later processing (for instance, if you want to select a group of images to copy somewhere else). The m
(image-mode-mark-file
) command will mark the current file in any Dired buffer(s) that display the current file’s directory. If no such buffer is open, the directory is opened in a new buffer. To unmark files, use the u
(image-mode-mark-file
) command. Finally, if you just want to copy the current buffers file name to the kill ring, you can use the w
(image-mode-copy-file-name-as-kill
) command.
If the image can be animated, the command RET
(image-toggle-animation
) starts or stops the animation. Animation plays once, unless the option image-animate-loop
is non-nil
. With f
(image-next-frame
) and b
(image-previous-frame
) you can step through the individual frames. Both commands accept a numeric prefix to step through several frames at once. You can go to a specific frame with F
(image-goto-frame
). Frames are indexed from 1. Typing a +
(image-increase-speed
) increases the speed of the animation, a -
(image-decrease-speed
) decreases it, and a r
(image-reverse-speed
) reverses it. The command a 0
(image-reset-speed
) resets the speed to the original value.
If Emacs was compiled with support for the ImageMagick library, it can use ImageMagick to render a wide variety of images. The variable imagemagick-enabled-types
lists the image types that Emacs may render using ImageMagick; each element in the list should be an internal ImageMagick name for an image type, as a symbol or an equivalent string (e.g., BMP
for .bmp
images). To enable ImageMagick for all possible image types, change imagemagick-enabled-types
to t
. The variable imagemagick-types-inhibit
lists the image types which should never be rendered using ImageMagick, regardless of the value of imagemagick-enabled-types
(the default list includes types like C
and HTML
, which ImageMagick can render as an image but Emacs should not). To disable ImageMagick entirely, change imagemagick-types-inhibit
to t
.
If Emacs doesn’t have native support for the image format in question, and image-use-external-converter
is non-nil
, Emacs will try to determine whether there are external utilities that can be used to transform the image in question to PNG before displaying. GraphicsMagick, ImageMagick and ffmpeg
are currently supported for image conversions.
The Image-Dired package can also be used to view images as thumbnails. See Image-Dired.