As the title says, I cannot use feh to open a PNG image. feh on this machine can’t open a JPG image either. Let’s see what’s wrong.

I should notice that this problem occured on a machine running Gentoo. :D

First, let’s check if feh is installed using my favorite tool called eix:

~ ❯❯❯ eix feh
[I] media-gfx/feh
     Available versions:  3.1.1 ~3.1.3 ~3.2 ~3.2.1^t {curl debug exif test xinerama}
     Installed versions:  3.1.1(11:11:04 PM 04/14/2019)(-curl -debug -exif -test -xinerama)
     Description:         A fast, lightweight imageviewer using imlib2

According to the above information, feh:3.1.1 is already installed. It also mentions that feh use imlib2 library.

~ ❯❯❯ eix media-libs/imlib2
[I] media-libs/imlib2
     Available versions:  1.5.1-r1 {+X bzip2 doc gif jpeg mp3 nls png +shm static-libs tiff zlib ABI_MIPS="n32 n64 o32" ABI_RISCV="lp64 lp64d" ABI_S390="32 64" ABI_X86="32 64 x32" CPU_FLAGS_X86="mmx sse2"}
     Installed versions:  1.5.1-r1(07:30:45 PM 01/15/2019)(X bzip2 nls shm zlib -doc -gif -jpeg -mp3 -png -static-libs -tiff ABI_MIPS="-n32 -n64 -o32" ABI_PPC="-32 -64" ABI_S390="-32 -64" ABI_X86="64 -32 -x32" CPU_FLAGS_X86="sse2 -mmx")
     Description:         Version 2 of an advanced replacement library for libraries like libXpm

Again, imlib2 is installed. However, if we look closely both ‘-jpeg’ and ‘-png’ aren’t built in imlib2.

Let’s fix this by explicitly setting the flags to include both ‘jpeg’ and ‘png’.

~ ❯❯❯ echo 'media-libs/imlib2 png jpeg' > /etc/portage/package.use/imlib2
~ ❯❯❯ emerge -av media-libs/imlib2

After imlib2 has been rebuilt, feh could open both jpeg and png files.