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