## header to provide surface and context
using Cairo
c = CairoRGBSurface(256,256);
cr = CairoContext(c);

save(cr);
set_source_rgb(cr,0.8,0.8,0.8);    # light gray
rectangle(cr,0.0,0.0,256.0,256.0); # background
fill(cr);
restore(cr);

save(cr);
## original example, following here
image = read_from_png("data/mulberry.png");
w = image.width; 
h = image.height;

pattern = CairoPattern(image);
pattern_set_extend(pattern, Cairo.EXTEND_REPEAT);

translate(cr, 128.0, 128.0);
rotate(cr, pi / 4);
scale(cr, 1 / sqrt(2), 1 / sqrt(2));
translate(cr, -128.0, -128.0);

m = CairoMatrix(w/256.0 * 5.0,0,0,h/256.0 * 5.0,0,0);
#matrix_init_scale (&matrix, w/256.0 * 5.0, h/256.0 * 5.0);

set_matrix(pattern, m);
set_source(cr, pattern);

rectangle(cr, 0, 0, 256.0, 256.0);
fill(cr);

## mark picture with current date
restore(cr);
move_to(cr,0.0,12.0);
set_source_rgb(cr, 0,0,0);
show_text(cr,Libc.strftime(time()));
write_to_png(c,"sample_imagepattern.png");
