You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

75 lines
1.5 KiB

  1. #include "config.h"
  2. #include "common.h"
  3. #if !defined HAVE_GETOPT_LONG
  4. # include "mygetopt.h"
  5. #elif defined HAVE_GETOPT_H
  6. # include <getopt.h>
  7. #endif
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <pipi.h>
  12. #if defined HAVE_GETOPT_LONG
  13. # define mygetopt getopt_long
  14. # define myoptind optind
  15. # define myoptarg optarg
  16. # define myoption option
  17. #endif
  18. #define MOREINFO "Try `%s --help' for more information.\n"
  19. int main(int argc, char *argv[])
  20. {
  21. char *srcname = NULL, *dstname = NULL;
  22. pipi_image_t *src, *dst;
  23. int i, w = 0, h = 0;
  24. for(;;)
  25. {
  26. int option_index = 0;
  27. static struct myoption long_options[] =
  28. {
  29. { "geometry", 1, NULL, 'g' },
  30. };
  31. int c = mygetopt(argc, argv, "g:", long_options, &option_index);
  32. if(c == -1)
  33. break;
  34. switch(c)
  35. {
  36. case 'g':
  37. w = atoi(myoptarg);
  38. if(strchr(myoptarg, 'x'))
  39. h = atoi(strchr(myoptarg, 'x') + 1);
  40. break;
  41. default:
  42. fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c);
  43. printf(MOREINFO, argv[0]);
  44. return EXIT_FAILURE;
  45. }
  46. }
  47. for(i = myoptind; i < argc; i++)
  48. {
  49. if(!srcname)
  50. srcname = argv[i];
  51. else
  52. dstname = argv[i];
  53. }
  54. src = pipi_load(srcname);
  55. dst = pipi_resize(src, w, h);
  56. pipi_save(dst, dstname);
  57. pipi_free(src);
  58. pipi_free(dst);
  59. return 0;
  60. }