summaryrefslogtreecommitdiffstats
path: root/src/image.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/image.c')
-rw-r--r--src/image.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/image.c b/src/image.c
index d85c9fd..3c5d98f 100644
--- a/src/image.c
+++ b/src/image.c
@@ -46,10 +46,13 @@ image_new(const char *file_name)
return NULL;
}
- image->fp = fopen(file_name, "wb");
- if (!image->fp) {
- printf(_("Error: Cannot open \"%s\" for writing\n"), file_name);
- return image_destroy(&image);
+ if (strcmp(file_name, "-") != 0) {
+ image->fp = fopen(file_name, "wb");
+ if (!image->fp) {
+ printf(_("Error: Cannot open \"%s\" for writing\n"),
+ file_name);
+ return image_destroy(&image);
+ }
}
image->png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
@@ -63,7 +66,11 @@ image_new(const char *file_name)
return image_destroy(&image);
}
- png_init_io(image->png_ptr, image->fp);
+ if (image->fp) {
+ png_init_io(image->png_ptr, image->fp);
+ } else {
+ png_init_io(image->png_ptr, stdout);
+ }
return image;
}
@@ -107,7 +114,9 @@ image_destroy(struct image **image_p)
image = *image_p;
- fclose(image->fp);
+ if (image->fp) {
+ fclose(image->fp);
+ }
png_destroy_write_struct(&image->png_ptr, &image->info_ptr);
free(image);
return image = NULL;