#include "config.h" #include "common.h" #if !defined HAVE_GETOPT_LONG # include "mygetopt.h" #elif defined HAVE_GETOPT_H # include #endif #include #include #include #include #if defined HAVE_GETOPT_LONG # define mygetopt getopt_long # define myoptind optind # define myoptarg optarg # define myoption option #endif #define MOREINFO "Try `%s --help' for more information.\n" int main(int argc, char *argv[]) { char *srcname = NULL, *dstname = NULL; pipi_image_t *src, *dst; int i, w = 0, h = 0; for(;;) { int option_index = 0; static struct myoption long_options[] = { { "geometry", 1, NULL, 'g' }, }; int c = mygetopt(argc, argv, "g:", long_options, &option_index); if(c == -1) break; switch(c) { case 'g': w = atoi(myoptarg); if(strchr(myoptarg, 'x')) h = atoi(strchr(myoptarg, 'x') + 1); break; default: fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c); printf(MOREINFO, argv[0]); return EXIT_FAILURE; } } for(i = myoptind; i < argc; i++) { if(!srcname) srcname = argv[i]; else dstname = argv[i]; } src = pipi_load(srcname); dst = pipi_resize(src, w, h); pipi_save(dst, dstname); pipi_free(src); pipi_free(dst); return 0; }