summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominic Radermacher <blip@mockmoon-cybernetics.ch>2020-11-30 10:13:14 +0100
committerDominic Radermacher <blip@mockmoon-cybernetics.ch>2020-11-30 10:13:14 +0100
commit96c1d5c6b957740e006af9f62602ef9dbf830187 (patch)
treece21bdf94b7306e6956512166cf165fc40605fb6
parent87a8e8ff812a075477f2c792d0e7a48260842714 (diff)
images can now also be read from stdin (thanks to Siim Salonen)
-rw-r--r--src/ptouch-print.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/ptouch-print.c b/src/ptouch-print.c
index 145e647..d45b938 100644
--- a/src/ptouch-print.c
+++ b/src/ptouch-print.c
@@ -126,15 +126,24 @@ gdImage *image_load(const char *file)
FILE *f;
gdImage *img=NULL;
- if ((f = fopen(file, "rb")) == NULL) { /* error cant open file */
- return NULL;
+ if (!strcmp(file, "-")) {
+ f = stdin;
+ } else {
+ f = fopen(file, "rb");
}
- if (fread(d, sizeof(d), 1, f) != 1) {
+ if (f == NULL) { /* error could not open file */
return NULL;
}
- rewind(f);
- if (memcmp(d, png, 8) == 0) {
+ if (fseek(f, 0L, SEEK_SET)) { /* file is not seekable. eg 'stdin' */
img=gdImageCreateFromPng(f);
+ } else {
+ if (fread(d, sizeof(d), 1, f) != 1) {
+ return NULL;
+ }
+ rewind(f);
+ if (memcmp(d, png, 8) == 0) {
+ img=gdImageCreateFromPng(f);
+ }
}
fclose(f);
return img;