I am writing a minor mode which involves fetching some pictures from url and displaying them, but some of them are way too big to fit an emacs window.

How could I manage to limit the visual size of the displayed picture ?

For now I am using something like

(insert-image (create-image pic nil t))

for display, where pic is a jpeg image raw data as a string.

I spent a lot of time browsing google and couldn't find a tutorial, docs or a code example that would help me rescaling my images.
The GNU Emacs Lisp reference is quite obscure and confusing and doesn't contain much examples.

3 Answers 3


Fist you should check whether imagemagick-support is compiled into emacs. If (image-type-available-p 'imagemagick) returns non-nil you are fine (thanks to deb0ch for clarification).

Afterwards you can create images with type imagemagick and property :height and/or :width: (create-image "~/test.png" 'imagemagick nil :height 100)

See the manual page on ImageMagick images.

  • 1
    Just tested on an emacs compiled without imagemagick and checking for imagemagick support using (imagemagick-types) doesn't work: the function is void. Instead, check for its existence using (image-type-available-p 'imagemagick).
    – deb0ch
    Aug 25, 2016 at 8:38

The :width and :height keywords are available to scale the image only for the image type imagemagick.

My understanding of the documentation is that rather than using "convenience functions" such as create-image and insert-image you have to directly build an image descriptor and put it as the display text property of the position where you want to display the image.

Here's an example (displaying the image /usr/share/zenity/zenity.png at position 1 with a width of 100 pixels):

(put-text-property 1 2 'display (cons 'image
 '(:type imagemagick :file  "/usr/share/zenity/zenity.png" :width 100)))

Edit: as shown in @Tobias' answer, and contrary to what I say above, you can actually use "convenience functions".


I suggest that you use convert from ImageMagick to Resize or Scale images.

Alternatively, you can pass :scale to create-image or use (setf (image-property my-image :scale) ...).

  • Thanks for your answer ! Though Emacs is built with libmagickWand support, isn't there a way of doing that from inside emacs ? I saw something along those lines there with the :width, :max-width, :height and :max-height properties, but did not understand how to use it.
    – deb0ch
    Aug 11, 2016 at 16:40

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.