1

I have a problem loading PNG images in Gtk3. I have broken image symbols in my ToolButtons and after some investigation it appears that it comes from GdkPixbuf not being able to read the PNG files.

I have reproduced the problem with the python console

>>> from gi.repository import GdkPixbuf
>>> print(GdkPixbuf)
<gi.module.DynamicModule 'GdkPixbuf' from '/home/user1/ctcils/dusserm/applications/gobject-introspection/1.40.0/lib/girepository-1.0/GdkPixbuf-2.0.typelib'>
>>> GdkPixbuf.Pixbuf.new_from_file("/home/user1/ctcils/dusserm/applications/pycharm-community-3.4.1/bin/pycharm.png")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
gi._glib.GError: Couldn't recognize the image file format for file '/home/user1/ctcils/dusserm/applications/pycharm-community-3.4.1/bin/pycharm.png'

Many of the problems I faced in the last days were due to the fact we had to compile Gtk3, pygobject and all their dependencies and to install them in non-standard directories. I suspect a problem with the gobject introspection (the last from a long list).

Michael Dussere
  • 498
  • 7
  • 25
  • How did you go about building and installing these libs to non-standard directories? – Simon Feltman Aug 05 '14 at 06:21
  • I used the traditional cofigure/make/make install with the option --prefix. By non-standard I just mean that each library is installed in a specific directory on the NFS (some are installed in my home directory for the moment) and not on a common directory like /usr/local. – Michael Dussere Aug 05 '14 at 07:10
  • It seems that it is recommended to use JHbuild but we don't have a web access on the servers where we are installing. – Michael Dussere Aug 05 '14 at 07:15

3 Answers3

1

Not a full answer but some debugging tips: Check what image loaders gdk-pixbuf is providing (see also What image formats are supported by Gdk-Pixbuf (Gtk-Image?) by Default?). A Python snippet to check this:

from gi.repository import GdkPixbuf
for fmt in GdkPixbuf.Pixbuf.get_formats():
    print(fmt.get_extensions())

If nothing shows up, gdk-pixbuf is not finding any loaders which probably has something to do with the install location (--prefix and/or --libdir configure options). Verify you have loaders installed into the location gdk-pixbuf expects to find them (especially the png loader). This should be something like: <prefix>/lib[64]/gdk-pixbuf-2.0/<version>/loaders

See also: https://developer.gnome.org/gdk-pixbuf/stable/gdk-pixbuf-query-loaders.html

Community
  • 1
  • 1
Simon Feltman
  • 1,120
  • 7
  • 8
  • Looks like everything is in place. Pixbuf.get_formats returns a full list of image formats containing [png]. gdk-pixbuf-query-loaders has an entrey for png that points to libpixbufloader-png.so location. libpixbufloader-png.so is in place in the loaders directory. I checked for its dependencies with ldd and it looks fine. The loader-cache file is in place. I tried to setup GDK_PIXBUF_MODULEDIR and LD_LIBRARY_PATH without success. – Michael Dussere Aug 06 '14 at 07:22
  • I have 2 libpng installed in my system, libpng12.so.0.49.0 and libpng.so.3.49.0. libpixbufloader-png.so depends on libpng12. Is it normal ? During the configure I saw that it was looking for libpng16 in priority and that libpng12 was just a fallback. Could it be an explanation ? – Michael Dussere Aug 06 '14 at 07:27
  • Thanks for your help. Do you know if there is a real dependence between pixbuf and a specific version of libpng ? – Michael Dussere Aug 06 '14 at 11:34
1

I got a similar error with unusual prefix, and solved it by setting XDG_DATA_DIRS, which I didn't have set.

export XDG_DATA_DIRS=.../usr/share

Source: https://bugs.gentoo.org/644136

Alexey Sokolov
  • 109
  • 1
  • 6
-1

It seems that the problem was due to the PNG library itself. I am quite surprised considering that it comes from a regular CentOS rpm libpng-1.2.49-1.el6_2.x86_64 and that PNG is a stable standard for ages. In addition we did not have the problem with GTK2 that was using the same lib I suppose...

Anyway, I compiled a bright new libpng 1.6.2 from the sources, I re-configured and re-installed gdk-pixbuf and now it works.

Michael Dussere
  • 498
  • 7
  • 25