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
RevLine 
[14885]1/* There is no licence for this, I don't care what you do with it */
[12321]2#include <stdio.h>
3#include <stdlib.h>
4
[14885]5#include <webkit/webkit.h>
[12321]6
7#define WIDTH 2000
8
9/* compile with:
[14885]10gcc `pkg-config --cflags --libs webkit-1.0` -o webkit-image-gtk webkit-image-gtk.c
[12321]11*/
12
13static void
14on_finished (WebKitWebView *view, WebKitWebFrame *frame)
15{
[14885]16 GdkPixmap *pixmap;
17 GdkColormap *cmap;
18 GdkPixbuf *pixbuf;
19 gchar *buffer;
20 gsize size;
[12321]21
[14885]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);
[12321]26
[14885]27 gdk_pixbuf_save_to_buffer (pixbuf, &buffer, &size, "png", NULL, NULL);
[12321]28
[14885]29 fwrite (buffer, 1, size, stdout);
[12321]30
[14885]31 exit (1);
[12321]32}
33
34int main (int argc, char **argv)
35{
[14885]36 GtkWidget *window;
37 GtkWidget *view;
[12321]38
[14885]39 if (argc != 2)
40 exit (20);
[12321]41
[14885]42 gtk_init (&argc, &argv);
[12321]43
[14885]44 window = gtk_window_new (GTK_WINDOW_POPUP);
[12321]45
[14885]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");
[12321]51
[14885]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);
[12321]56
[14885]57 gtk_widget_show_all (window);
[12321]58
[14885]59 g_signal_connect (G_OBJECT (view), "load-finished",
60 G_CALLBACK (on_finished), NULL);
61
62 gtk_main ();
63 return 0;
[12321]64}
Note: See TracBrowser for help on using the repository browser.