An important point about the colormap. If the source drawable does not have a colormap, a compatible one needs to be provided. If you are capturing contents of a window then GdkWindow::get_colormap() method can be used.

 1: <?php
 2
:   // Here we create a pixmap, draw something on it, then convert it
 
3:   // to a GdkPixbuf and scale and composite it over a checkerboard
 
4:   // pattern.
 
5
 
6:   // $window is a GtkWindow we created previously
 
7:   $window->realize();
 
8
 
9:   $pm = &new GdkPixmap($window->window300300);
10:   $win $window->window;
11:   $cmap $window->get_colormap();
12:   $c $cmap->alloc('orange');
13:   $c1 $cmap->alloc('white');
14:   $c2 $cmap->alloc('gray50');
15:   $gc $win->new_gc();
16:   $gc->foreground $c;
17:   $gc->line_width 3;
18:   gdk::draw_rectangle($pm$window->style->white_gctrue00300300);
19:   gdk::draw_line($pm$gc00300300);
20:   gdk::draw_line($pm$gc03003000);
21:   gdk::draw_arc($pm$gctrue10010010010064 4564 90);
22:   gdk::draw_arc($pm$gctrue10010010010064 22564 90);
23
24:   $pixbuf gdkpixbuf::get_from_drawable(null$pm$cmap,
25:                                          0000300300);
26:   $pixbuf $pixbuf->composite_color_simple(500200GDK_INTERP_BILINEAR,
27:                                             2008$c1->pixel$c2->pixel);
28
29:   // Display pixbuf as before
30?>