+ g_type_init ();
+
+ if (!g_thread_supported ())
+ g_thread_init (NULL);
+
+ if (!ev_init ())
+ return -1;
+
+ file = g_file_new_for_commandline_arg (input);
+ document = evince_thumbnailer_get_document (file);
+ g_object_unref (file);
+
+ if (!document) {
+ ev_shutdown ();
+ return -2;
+ }
+
+ if (!EV_IS_DOCUMENT_THUMBNAILS (document)) {
+ g_object_unref (document);
+ ev_shutdown ();
+ return -2;
+ }
+
+ if (EV_IS_ASYNC_RENDERER (document)) {
+ struct AsyncData data;
+
+ gtk_init (&argc, &argv);
+
+ data.document = document;
+ data.output = output;
+ data.size = size;
+
+ g_thread_create ((GThreadFunc) evince_thumbnail_pngenc_get_async,
+ &data, FALSE, NULL);
+
+ gtk_main ();
+
+ g_object_unref (document);
+ ev_shutdown ();
+
+ return data.success ? 0 : -2;
+ }
+
+ if (!evince_thumbnail_pngenc_get (document, output, size)) {
+ g_object_unref (document);
+ ev_shutdown ();