#!/usr/bin/perl use warnings; use strict; use Cairo; # Check we can use PNGs if (! Cairo::HAS_PNG_FUNCTIONS) { die "png backend not supported"; } # Create a drawing surface. my $surface = Cairo::ImageSurface->create ('argb32', 100, 100); # Create a drawing context. my $cr = Cairo::Context->create ($surface); # Create a rectangle $cr->rectangle (0, 0, 100, 100); # Set the colours to red=0, green=0, blue=0. $cr->set_source_rgb (0, 0, 0); # Fill the rectangle. $cr->fill (); # The name of the output file. my $png = 'simple-image.png'; # Write the surface to the png file specified by $png. $surface->write_to_png ($png);