File: webkit-image-gtk.c

package info (click to toggle)
webkit-image 0.0.svn25399-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch, wheezy
  • size: 120 kB
  • ctags: 32
  • sloc: cpp: 137; ansic: 72; sh: 61; makefile: 51
file content (54 lines) | stat: -rw-r--r-- 1,193 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* There is no licence for this, I don't care what you do with it */
#include <stdlib.h>
#include <unistd.h>

#include <gio/gunixoutputstream.h>
#include <webkit/webkit.h>

/* compile with:
 * gcc -o webkit-image-gtk webkit-image-gtk.c `pkg-config --cflags --libs webkit-1.0 gio-unix-2.0`
 * Requires GTK+ 2.20 and WebKitGtk+ 1.1.1
 */

static void
on_finished (WebKitWebView      *view,
             WebKitWebFrame     *frame,
             GtkOffscreenWindow *window)
{
	GdkPixbuf *pixbuf;
	GOutputStream *stream;

	pixbuf = gtk_offscreen_window_get_pixbuf (window);

	stream = g_unix_output_stream_new (STDOUT_FILENO, TRUE);
	gdk_pixbuf_save_to_stream (pixbuf, stream, "png", NULL, NULL, NULL);

	exit (1);
}

int
main (int    argc,
      char **argv)
{
	GtkWidget *window;
	GtkWidget *view;

	if (argc != 2)
		exit (20);

	gtk_init (&argc, &argv);

	window = gtk_offscreen_window_new ();

	view = webkit_web_view_new ();
	webkit_web_view_load_uri (WEBKIT_WEB_VIEW (view), argv[1]);
	gtk_container_add (GTK_CONTAINER (window), view);

	gtk_widget_show_all (window);

	g_signal_connect (view, "load-finished",
	                  G_CALLBACK (on_finished), window);

	gtk_main ();
	return 0;
}