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
|
# File 'ext/imgclip/imgclip.c', line 5
static VALUE clipboard_to_file(VALUE _self, VALUE path) {
char* c_path = StringValueCStr(path);
Check_Type(path, T_STRING);
GtkClipboard *clipboard;
GdkPixbuf *pixbuf;
clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
pixbuf = gtk_clipboard_wait_for_image(clipboard);
if (pixbuf == NULL) {
rb_raise(rb_eArgError, "Clipboard content could not be converted into an image.");
}
GError *gerror = NULL;
char* image_type = "jpeg";
gdk_pixbuf_save(pixbuf, c_path, image_type, &gerror, NULL);
if (gerror) {
g_error_free(gerror);
rb_raise(rb_eException, "Unable to save clipboard image to %s: %s\n", c_path, gerror->message);
}
if (pixbuf != NULL) {
g_object_unref(pixbuf);
}
return path;
}
|