summaryrefslogtreecommitdiff
path: root/ws2a/gencaptcha.c
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2016-05-10 15:21:29 -0400
committerAlexander Pickering <alexandermpickering@gmail.com>2016-05-10 15:21:29 -0400
commit5d5d288bb595ae2297c99071f4db2a095c3ed101 (patch)
tree1579982b5d0683cd39802096ddbc9ba351d45416 /ws2a/gencaptcha.c
parent0d64b64e03261606ca5b61b02123c0fe0dd2a36e (diff)
downloadwebpage-5d5d288bb595ae2297c99071f4db2a095c3ed101.tar.gz
webpage-5d5d288bb595ae2297c99071f4db2a095c3ed101.tar.bz2
webpage-5d5d288bb595ae2297c99071f4db2a095c3ed101.zip
Printed captchas to stream correctly
Diffstat (limited to 'ws2a/gencaptcha.c')
-rw-r--r--ws2a/gencaptcha.c39
1 files changed, 29 insertions, 10 deletions
diff --git a/ws2a/gencaptcha.c b/ws2a/gencaptcha.c
index 7073362..8141ee5 100644
--- a/ws2a/gencaptcha.c
+++ b/ws2a/gencaptcha.c
@@ -56,7 +56,7 @@ int main(){
int barraldis1 = rand()%10;
int barraldis2 = rand()%10;
- int arcdis = rand()%100;
+ int arcdis = (rand()%99)+1;
char command[1024];
sprintf(command,"convert -background white -fill black -pointsize 48 label:\"%s\" \"../ws2a/captchas/%s.png\"",randwords,randwords);
system(command);
@@ -64,20 +64,39 @@ int main(){
system(command);
sprintf(command,"convert \"../ws2a/captchas/%s.png\" -virtual-pixel White -distort Arc %d \"../ws2a/captchas/%s.png\"",randwords,arcdis,randwords);
system(command);
-
+ sleep(1);
FILE* imgfile;
char filepath[100];
- sprintf(filepath,"../ws2a/captchas/%s.png",randwords);
- imgfile = fopen(filepath,"r");
+ sprintf(filepath,"..\\ws2a\\captchas\\%s.png",randwords);
+ //printf("Filepath:%s",filepath);
+ imgfile = fopen(filepath,"rb");
if(imgfile == NULL){
printf("Unable to open file!");
return 1;
}
- while(!feof(imgfile)){
- char c = fgetc(imgfile);
- if(feof(imgfile)){
- return 0;
- }
- putchar(c);
+ fseek(imgfile,0,SEEK_END);
+ unsigned long filelen = ftell(imgfile);
+ //printf("File length:%lu",filelen);
+ fseek(imgfile,0,SEEK_SET);
+ //fwrite(imgfile,1,filelen,stdout);
+
+ char* buffer = malloc(filelen+1);
+ if(buffer == NULL){
+ printf("Memory error!");
+ return 1;
+ }
+ fread(buffer, filelen, 1, imgfile);
+ int i = 0;
+ while(i < filelen){
+ printf("%c",buffer[i]);
+ i++;
+ }
+ free(buffer);
+ /*
+ char c;
+ while((c = fgetc(imgfile)) && !feof(imgfile)){
+ printf("char is:something\n",c);
+ //putchar(c);
}
+ */
}