Table of Contents
Some might want to enable PNG image support for his/her Emacs on Windows because AUCTeX Preview LaTeX feature or Org LaTeX preview feature may require it. This post assumes you are using official GNU Emacs, and not some bundled versions. (In fact, bundled versions might bundle relevant dlls for you so that you don’t have to do it manually.)
1. How do I check if PNG support is enabled?
If enabled, when you drag and drop a PNG image file to an Emacs frame, the image will be displayed in that buffer. If not enabled, some gibberish text will be shown instead and Emacs will say
Cannot display image: (Invalid image specification)
2. How do I enable it?
As for the latest stable version of GNU Emacs as of this writing, which is GNU Emacs 24.3.1, you only need to copy the library file
libpng14-14.dll (and also
zlib1.dll) into the Emacs bin folder (the bin folder where
emacs.exe is). The files can be found in
C:\Program Files\Inkscape (or
C:\Program Files (x86)\Inkscape) if you have installed Inkscape, and also in
C:\Program Files\GNU\GnuPG if you have installed GNU GnuPG (which I install with the gpg4win installer). Don’t forget to restart Emacs.
In case later versions come out after I write this article and I don’t get to update this, here’s how for later versions of GNU Emacs: first evaluate the following elisp code:
(cdr (assq 'png dynamic-library-alist))
the evaluation result will be something like
("libpng14-14.dll" "libpng14.dll"), then it means that you need to copy the library file
libpng14.dll into your Emacs bin folder.
Another way to see which library files to get is to read a relevant section in GNU Emacs Windows FTP readme.
3.1. elisp code to check PNG support programmatically
3.2. things that don’t enable PNG support
According to my test with GNU Emacs 24.3.1, following things don’t successfully enable PNG support.
- Adding the path to the folder containing the appropriate libpng dll file to
exec-path(Elisp variable) and/or
PATH(Windows environment variable).
- Copying an older version of libpng dll into Emacs bin. (GnuWin32 ones are likely to be old.)
image-library-alist) in the hope that it may make Emacs recognize the old libpng file (in 2).
With 3, error message is something like:
PNG warning: Application was compiled with png.h from libpng-1.4.3 PNG warning: Application is running with png.c from libpng-1.2.37 PNG error: Incompatible libpng version in application and library ...