1 /* cairo-tutorial-png.h - a tutorial framework for cairo to write a PNG image
3 * Copyright © 2005, Carl Worth
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
35 draw (cairo_t *cr, int width, int height);
38 main (int argc, char **argv)
40 cairo_surface_t *surface;
42 char *filename, *dash;
44 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
47 cr = cairo_create (surface);
49 draw (cr, WIDTH, HEIGHT);
51 filename = strdup (argv[0]);
52 assert (filename != NULL);
54 dash = strrchr (filename, '-');
56 if (strcmp (dash, "-png") == 0) {
60 new_filename = malloc (strlen (filename) + 5);
61 sprintf (new_filename, "%s.png", filename);
63 filename = new_filename;
66 cairo_surface_write_to_png (surface, filename);
70 cairo_surface_destroy (surface);