gdtopng.c 965 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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: gdtopng filename.gd filename.png\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 = gdImageCreateFromGd (in);
  24. fclose (in);
  25. if (!im)
  26. {
  27. fprintf (stderr, "Input is not in GD 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. gdImagePng (im, out);
  38. fclose (out);
  39. gdImageDestroy (im);
  40. return 0;
  41. }