"Fossies" - the Fresh Open Source Software Archive

Member "libgd-2.3.2/examples/png2avif.c" (4 Mar 2021, 1080 Bytes) of package /linux/www/libgd-2.3.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    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 }