#include #include #include // PicThumbs // created by Alex Kennberg. January 18, 2002. // finds images in the current directory and creates an html file // that lists them as thumb nails. #define MAX_FILENAME 128 #define MAX_PICTURES 1024 #define FILE_HEADER "\x0D\x0APicThumbs\x0D\x0A\x0D\x0A
\x0D\x0A\x0D\x0A" #define FILE_FOOTER "\x0D\x0A\x0D\x0A
\x0D\x0A\x0D\x0A\x0D\x0A" #define FILE_IMAGE "\x0D\x0A" // strings are used in case of percent char img_width[8] = "160"; char img_height[8] = "140"; char filedir[MAX_PATH]; int filenum; char filenames[MAX_PICTURES][MAX_FILENAME]; // goes through current durirectory and finds all jpegs findImages() { WIN32_FIND_DATA filedata; HANDLE filehandle; if ((filehandle = FindFirstFile(filedir, &filedata)) != INVALID_HANDLE_VALUE) { do { int i; char *n = filedata.cFileName; // scan through the name for file type .jpg or .jpeg for (i = 0; n[i]; i++) { if (tolower(n[i])=='.' && tolower(n[i+1])=='j' && tolower(n[i+2])=='p' && (tolower(n[i+3])=='g' || (tolower(n[i+3])=='e' && tolower(n[i+4])=='g'))) { strcpy(filenames[filenum++], n); break; } } // leave this here in case we have more file types if (filenum >= MAX_PICTURES) break; } while (FindNextFile(filehandle, &filedata)); } FindClose(filehandle); } main(int ac, char **av) { FILE *file; char fileout[MAX_PATH]; int count; int i; BOOL sort = 0; printf("PicThumbs.\n --- created by Alex Kennberg. January 18, 2002.\n"); for (i = 1; i < ac; i++) { if (av[i][0] == '-') { switch (av[i][1]) { case 's': sort = 1; break; case 'w': if (i + 1 >= ac) { printf("ERROR: bad argument %s\n", av[i]); return; } strcpy(img_width, av[++i]); break; case 'h': if (i + 1 >= ac) { printf("ERROR: bad argument %s\n", av[i]); return; } strcpy(img_height, av[++i]); break; default: printf("ERROR: unknown parameter %s\n", av[i]); } } } // make the file name 'index.html' GetCurrentDirectory(sizeof(filedir), filedir); strcpy(fileout, filedir); strcat(fileout, "\\picthumbs.html"); strcat(filedir, "\\*.*"); // kill it if exists unlink(fileout); // open it file = fopen(fileout, "wb"); if (!file) { printf("ERROR: failed to open %s\n", fileout); return; } // begin the file fprintf(file, FILE_HEADER); filenum = 0; findImages(); // sort the files if requested if (sort) qsort(filenames, filenum, MAX_FILENAME, (int(*)(const void*,const void*))strcmp); // lists the images in our HTML file for (count = 2, i = 0; i < filenum; i++) { if (count++ >= 2) { fprintf(file, "
\x0D\x0A"); count = 0; } fprintf(file, FILE_IMAGE, filenames[i], filenames[i], img_width, img_height); } // end the file fprintf(file, FILE_FOOTER); // close it fclose(file); }