1 /*****************************************************************************
2 * This file is part of gfxprim library. *
4 * Gfxprim is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Lesser General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2.1 of the License, or (at your option) any later version. *
9 * Gfxprim 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 GNU *
12 * Lesser General Public License for more details. *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with gfxprim; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301 USA *
19 * Copyright (C) 2009-2012 Cyril Hrubis <metan@ucw.cz> *
21 *****************************************************************************/
25 Uses gfxprim to render small image with defined string.
31 static const char help
[] = {
32 "usage: ttf2img -f font.ttf -i file.png -s string [-d debug_level]\n",
35 static void print_help(int i
)
41 int main(int argc
, char *argv
[])
43 const char *font_path
= NULL
;
44 const char *img_path
= NULL
;
45 const char *string
= "Foo Bar!";
46 int opt
, debug_level
= 0;
47 int img_w
= 400, img_h
= 100;
49 while ((opt
= getopt(argc
, argv
, "d:f:i:s:")) != -1) {
58 debug_level
= atoi(optarg
);
67 fprintf(stderr
, "Invalid paramter '%c'\n", opt
);
72 if (font_path
== NULL
|| img_path
== NULL
)
75 GP_SetDebugLevel(debug_level
);
77 GP_Pixmap
*pixmap
= GP_PixmapAlloc(img_w
, img_h
, GP_PIXEL_RGB888
);
79 GP_Pixel black_pixel
= GP_RGBToPixmapPixel(0x00, 0x00, 0x00, pixmap
);
80 GP_Pixel white_pixel
= GP_RGBToPixmapPixel(0xff, 0xff, 0xff, pixmap
);
82 GP_Fill(pixmap
, white_pixel
);
84 GP_TextStyle style
= GP_DEFAULT_TEXT_STYLE
;
86 style
.font
= GP_FontFaceLoad(font_path
, 27, 0);
88 GP_Text(pixmap
, &style
, img_w
/2, img_h
/2, GP_ALIGN_CENTER
|GP_VALIGN_CENTER
,
89 black_pixel
, white_pixel
, string
);
91 GP_SavePNG(pixmap
, img_path
, NULL
);
93 GP_PixmapFree(pixmap
);