When displaying images in Image mode the default seems to be to scale the image to fit completely within the frame. (Or within the document area of the frame to be more precise.) I find this inconvenient for images which are much taller than they are wide.

M-x describe-mode shows the command increase-image-size is bound, but many keystrokes may be required to scale the image appropriately. Within image-mode.el I found the command image-transform-fit-to-width which has the effect I want, but it is not bound. It is defined as follows:

(defun image-transform-fit-to-width ()
  "Fit the current image to the width of the current window.
This command has no effect unless Emacs is compiled with
ImageMagick support."
  (setq image-transform-resize 'fit-width)

I could bind this in my init.el of course, and may still do, but I think I'd like to find a way to have the images scaled in this way by default. Can it be done?

1 Answer 1


There is a variable image-auto-resize which you can customize to fit-width:

image-auto-resize is a variable defined in ‘image-mode.el’.
Its value is ‘fit-width’
Original value was t

  You can customize this variable.
  This variable was introduced, or its default value was changed, in
  version 27.1 of Emacs.
  Probably introduced at or before Emacs version 27.1.

Non-nil to resize the image upon first display.
Its value should be one of the following:
 - nil, meaning no resizing.
 - t, meaning to fit the image to the window height and width.
 - ‘fit-height’, meaning to fit the image to the window height.
 - ‘fit-width’, meaning to fit the image to the window width.
 - A number, which is a scale factor (the default size is 1).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.