pngtogd.c 967 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include <stdio.h>
  2. #include "gd.h"
  3. /* A short program which converts a .png file into a .gd file, for
  4. your convenience in creating images on the fly from a
  5. basis image that must be loaded quickly. The .gd format
  6. is not intended to be a general-purpose format. */
  7. int
  8. main (int argc, char **argv)
  9. {
  10. gdImagePtr im;
  11. FILE *in, *out;
  12. if (argc != 3)
  13. {
  14. fprintf (stderr, "Usage: pngtogd filename.png filename.gd\n");
  15. exit (1);
  16. }
  17. in = fopen (argv[1], "rb");
  18. if (!in)
  19. {
  20. fprintf (stderr, "Input file does not exist!\n");
  21. exit (1);
  22. }
  23. im = gdImageCreateFromPng (in);
  24. fclose (in);
  25. if (!im)
  26. {
  27. fprintf (stderr, "Input is not in PNG format!\n");
  28. exit (1);
  29. }
  30. out = fopen (argv[2], "wb");
  31. if (!out)
  32. {
  33. fprintf (stderr, "Output file cannot be written to!\n");
  34. gdImageDestroy (im);
  35. exit (1);
  36. }
  37. gdImageGd (im, out);
  38. fclose (out);
  39. gdImageDestroy (im);
  40. return 0;
  41. }