source: osm/applications/editors/josm/plugins/wmsplugin/webkit-image-gtk.c@ 16431

Last change on this file since 16431 was 14885, checked in by tomhughes, 16 years ago

Updated version of webkit-image-gtk.c from original author. Closes #1429.

File size: 1.5 KB
Line 
1/* There is no licence for this, I don't care what you do with it */
2#include <stdio.h>
3#include <stdlib.h>
4
5#include <webkit/webkit.h>
6
7#define WIDTH 2000
8
9/* compile with:
10gcc `pkg-config --cflags --libs webkit-1.0` -o webkit-image-gtk webkit-image-gtk.c
11*/
12
13static void
14on_finished (WebKitWebView *view, WebKitWebFrame *frame)
15{
16 GdkPixmap *pixmap;
17 GdkColormap *cmap;
18 GdkPixbuf *pixbuf;
19 gchar *buffer;
20 gsize size;
21
22 pixmap = gtk_widget_get_snapshot (GTK_WIDGET (view), NULL);
23 cmap = gdk_colormap_get_system ();
24 pixbuf = gdk_pixbuf_get_from_drawable (NULL, GDK_DRAWABLE (pixmap), cmap,
25 0, 0, 0, 0, WIDTH, WIDTH);
26
27 gdk_pixbuf_save_to_buffer (pixbuf, &buffer, &size, "png", NULL, NULL);
28
29 fwrite (buffer, 1, size, stdout);
30
31 exit (1);
32}
33
34int main (int argc, char **argv)
35{
36 GtkWidget *window;
37 GtkWidget *view;
38
39 if (argc != 2)
40 exit (20);
41
42 gtk_init (&argc, &argv);
43
44 window = gtk_window_new (GTK_WINDOW_POPUP);
45
46 /* Check if compositing window manager is running, needs one for now */
47 if (gtk_widget_is_composited (window))
48 gtk_window_set_opacity (GTK_WINDOW (window), 0.0);
49 else
50 g_error ("This requires a compositing window manager for now");
51
52 view = webkit_web_view_new ();
53 webkit_web_view_open (WEBKIT_WEB_VIEW (view), argv[1]);
54 gtk_widget_set_size_request (view, WIDTH, WIDTH);
55 gtk_container_add (GTK_CONTAINER (window), view);
56
57 gtk_widget_show_all (window);
58
59 g_signal_connect (G_OBJECT (view), "load-finished",
60 G_CALLBACK (on_finished), NULL);
61
62 gtk_main ();
63 return 0;
64}
Note: See TracBrowser for help on using the repository browser.