mirror of
https://github.com/simon987/fastimagehash.git
synced 2025-12-16 23:59:02 +00:00
Add command line tool for testing, more work on the API
This commit is contained in:
59
imhash.c
Normal file
59
imhash.c
Normal file
@@ -0,0 +1,59 @@
|
||||
#include "fastimagehash.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
void print_usage() {
|
||||
printf("Using fastimagehash library v%s\n", FASTIMAGEHASH_VERSION);
|
||||
printf("Usage: imhash [FILE]...\n");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
if (argc < 3) {
|
||||
print_usage();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int do_phash = 0, do_ahash = 0, do_whash = 0, do_dhash = 0;
|
||||
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (strcmp(argv[i], "--phash") == 0) {
|
||||
do_phash = 1;
|
||||
} else if (strcmp(argv[i], "--ahash") == 0) {
|
||||
do_ahash = 1;
|
||||
} else if (strcmp(argv[i], "--whash") == 0) {
|
||||
do_whash = 1;
|
||||
} else if (strcmp(argv[i], "--dhash") == 0) {
|
||||
do_dhash = 1;
|
||||
} else {
|
||||
|
||||
uchar hash[9];
|
||||
char hashstr[17];
|
||||
|
||||
if (do_phash) {
|
||||
if (phash_file(argv[i], hash, 8, 4) == 0) {
|
||||
hash_to_hex_string_reversed(hash, hashstr, 8);
|
||||
printf("%s\tp:%s\n", argv[i], hashstr);
|
||||
}
|
||||
}
|
||||
if (do_ahash) {
|
||||
if (ahash_file(argv[i], hash, 8) == 0) {
|
||||
hash_to_hex_string_reversed(hash, hashstr, 8);
|
||||
printf("%s\ta:%s\n", argv[i], hashstr);
|
||||
}
|
||||
}
|
||||
if (do_dhash) {
|
||||
if (dhash_file(argv[i], hash, 8) == 0) {
|
||||
hash_to_hex_string_reversed(hash, hashstr, 8);
|
||||
printf("%s\td:%s\n", argv[i], hashstr);
|
||||
}
|
||||
}
|
||||
if (do_whash) {
|
||||
if (whash_file(argv[i], hash, 8, 0) == 0) {
|
||||
hash_to_hex_string_reversed(hash, hashstr, 8);
|
||||
printf("%s\tw:%s\n", argv[i], hashstr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user