From 4867144910a33314aa080037b228a3805299d051 Mon Sep 17 00:00:00 2001 From: handa Date: Tue, 27 Sep 2005 11:29:54 +0000 Subject: [PATCH] (dump_image): If FILTER is "-", print the image to stdout. --- example/mdump.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/example/mdump.c b/example/mdump.c index 3a5bfad..76c8416 100644 --- a/example/mdump.c +++ b/example/mdump.c @@ -88,6 +88,8 @@ So, the default behaviour is the same as specifying "cat > %s.png" as FILTER. + If FILTER is just "-", the PNG image is written to stdout. +
  • -a Enable anti-alias drawing. @@ -184,6 +186,8 @@ ¤Î¥Ù¡¼¥¹¥Í¡¼¥à¤ËÃÖ¤­´¹¤¨¤é¤ì¤ë¡£¤³¤Î¥×¥í¥°¥é¥à¤Î¥Ç¥Õ¥©¥ë¥È¤Î¿¶Éñ¤¤ ¤È¡¢FILTER ¤Ë "cat > %s.png" ¤ò»ØÄꤷ¤¿¾ì¹ç¤Î¿¶Éñ¤ÏƱ°ì¤Ç¤¢¤ë¡£ + ¤â¤· FILTER ¤¬Ã±¤Ë "-" ¤Ç¤¢¤ì¤Ð¡¢ PNG ²èÁü¤Ï stdout ¤Ë½ÐÎϤµ¤ì¤ë¡£ +
  • -a ¥¢¥ó¥Á¥¨¥¤¥ê¥¢¥¹½èÍý¤ò¹Ô¤¦¡£ @@ -388,14 +392,19 @@ dump_image (gdImagePtr image, char *filename, char *filter, if (filter) { - char *command = alloca (strlen (filename) + strlen (filter) + 1); + if (filter[0] == '-' && filter[1] == '\0') + fp = stdout; + else + { + char *command = alloca (strlen (filename) + strlen (filter) + 1); - sprintf (command, filter, filename); - fp = popen (command, "w"); - if (! fp) - FATAL_ERROR ("Can't run the command \"%s\"\n", command); - if (! quiet_mode) - printf ("Running \"%s\" ... ", command); + sprintf (command, filter, filename); + fp = popen (command, "w"); + if (! fp) + FATAL_ERROR ("Can't run the command \"%s\"\n", command); + if (! quiet_mode) + printf ("Running \"%s\" ... ", command); + } } else { @@ -411,7 +420,8 @@ dump_image (gdImagePtr image, char *filename, char *filter, /* Generate PNG. */ gdImagePng (image, fp); - fclose (fp); + if (fp != stderr) + fclose (fp); if (! quiet_mode) printf (" done (%dx%d)\n", image->sx, image->sy); } -- 1.7.10.4