#include <gdk-pixbuf/gdk-pixbuf.h>

static int opt_width  = -1;
static int opt_height = -1;

static const GOptionEntry
options[] = {
  { "width",  'w', 0, G_OPTION_ARG_INT, &opt_width, },
  { "height", 'h', 0, G_OPTION_ARG_INT, &opt_height, },
  { NULL }
};

int
main (int argc, char **argv)
{
  GError *error = NULL;
  GOptionContext *context;
  int i;

  g_type_init ();

  context = g_option_context_new ("FILE...");
  g_option_context_add_main_entries (context, options, NULL);
  if (!g_option_context_parse (context, &argc, &argv, &error))
    g_error ("%s", error->message);
  g_option_context_free (context);

  for (i = 1; i < argc; i++)
    {
      const char *filename = argv[i];
      GdkPixbuf *pixbuf;

      g_printerr ("%s\n", filename);

      error = NULL;
      if (opt_width != -1 || opt_height != -1)
	pixbuf = gdk_pixbuf_new_from_file_at_size (filename, opt_width, opt_height, &error);
      else
	pixbuf = gdk_pixbuf_new_from_file (filename, &error);
      if (pixbuf)
	{
	  g_printerr ("   OK\n");
	  g_object_unref (pixbuf);
	}
      else
	{
	  g_printerr ("   %s\n", error->message);
	  g_error_free (error);
	}
    }

  return 0;
}

// cc -Wall -O2 `pkg-config --cflags --libs gtk+-2.0` pixbuf-load.c -o pixbuf-load
