from gi.repository import GLib, GObject, Gio
from gi.repository import GdkPixbuf

import sys

def on_size_prepared(loader, width, height, filename):
    print "file '%s' size %d x %d" % (filename, width, height)

def main(filename):
    loader = GdkPixbuf.PixbufLoader()
    loader.connect('size-prepared', on_size_prepared, filename)

    f = Gio.File.new_for_path(filename)
    stream = f.read(None)
    if not stream:
        return

    loading = True
    while loading:
        buf = stream.read_bytes(8192, None)
        if buf.get_size() <= 0:
            loading = False
            stream.close(None)
            loader.close()
        else:
            loader.write_bytes(buf)

if __name__ == '__main__':
    main(sys.argv[1])
    sys.exit(0)
