"Fossies" - the Fresh Open Source Software Archive

Member "libgd-2.3.2/examples/jpeg2avif.c" (4 Mar 2021, 1050 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 .jpg file into a .avif 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: jpeg2avif filename.jpg filename.avif\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, "Error: input file %s does not exist.\n", argv[1]);
   30         exit(1);
   31     }
   32 
   33     im = gdImageCreateFromJpeg(in);
   34     fclose(in);
   35     if (!im) {
   36         fprintf(stderr, "Error: input file %s is not in JPEG format.\n", argv[1]);
   37         exit(1);
   38     }
   39 
   40     out = fopen(argv[2], "wb");
   41     if (!out) {
   42         fprintf(stderr, "Error: can't write to output file %s\n", argv[2]);
   43         gdImageDestroy(im);
   44         exit(1);
   45     }
   46 
   47     fprintf(stderr, "Encoding...\n");
   48 
   49     gdImageAvif(im, out);
   50 
   51     printf("Wrote outfile %s.\n", argv[2]);
   52 
   53     fclose(out);
   54     gdImageDestroy(im);
   55 
   56     return 0;
   57 }