| 1 |
/** |
| 2 |
* A short program which converts a .avif file into a .jpg file - |
| 3 |
* just to get a little practice with the basic functionality. |
| 4 |
*/ |
| 5 |
|
| 6 |
#ifdef HAVE_CONFIG_H |
| 7 |
#include "config.h" |
| 8 |
#endif /* HAVE_CONFIG_H */ |
| 9 |
|
| 10 |
#include <stdio.h> |
| 11 |
#include <stdlib.h> |
| 12 |
|
| 13 |
#include "gd.h" |
| 14 |
|
| 15 |
int main(int argc, char **argv) |
| 16 |
{ |
| 17 |
gdImagePtr im; |
| 18 |
FILE *in, *out; |
| 19 |
|
| 20 |
if (argc != 3) { |
| 21 |
fprintf(stderr, "Usage: avif2jpeg infile.avif outfile.jpg\n"); |
| 22 |
exit(1); |
| 23 |
} |
| 24 |
|
| 25 |
printf("Reading infile %s\n", argv[1]); |
| 26 |
|
| 27 |
in = fopen(argv[1], "rb"); |
| 28 |
if (!in) { |
| 29 |
fprintf(stderr, "\nError: input file %s does not exist.\n", argv[1]); |
| 30 |
exit(1); |
| 31 |
} |
| 32 |
|
| 33 |
im = gdImageCreateFromAvif(in); |
| 34 |
fclose(in); |
| 35 |
if (!im) { |
| 36 |
fprintf(stderr, "\nError: input file %s is not in AVIF format.\n", argv[1]); |
| 37 |
exit(1); |
| 38 |
} |
| 39 |
|
| 40 |
out = fopen(argv[2], "wb"); |
| 41 |
if (!out) { |
| 42 |
fprintf(stderr, "\nError: can't write to output file %s\n", argv[2]); |
| 43 |
gdImageDestroy(im); |
| 44 |
exit(1); |
| 45 |
} |
| 46 |
|
| 47 |
gdImageJpeg(im, out, 75); |
| 48 |
|
| 49 |
printf("Wrote outfile %s.\n", argv[2]); |
| 50 |
|
| 51 |
fclose(out); |
| 52 |
gdImageDestroy(im); |
| 53 |
|
| 54 |
return 0; |
| 55 |
} |