All pastes #572136 Raw Edit

Untitled

public c v1 · immutable
·published 2007-06-17 15:37 UTC
rendered paste body
#include <stdio.h>#include <stdlib.h>#include <gd.h>#include <time.h>/*         Dbyt3r  ** Kick ARSE!*/int main(int argc, char *argv[]){ time_t now = time(NULL) * 1000; gdImagePtr captcha; FILE *fp; int train = 1; fp = fopen("C:\\Program Files\\xampp\\htdocs\\delicious.png","rb"); captcha = gdImageCreateFromPng(fp); fclose(fp); int width = gdImageSX(captcha); int height = gdImageSY(captcha); int x,y; for(x=0;x<width;++x){         for(y=0;y<height;++y){                 if(gdImageGetPixel(captcha,x,y) == 2){                                                 gdImageSetPixel(captcha,x,y,0);                 }         } } for(x=0;x<width;++x){         for(y=0;y<height;++y){                 if(gdImageGetPixel(captcha,x,y) != 0){                                                 int pop= getPopularity(x,y,captcha);                                                 if(pop < 4){gdImageSetPixel(captcha,x,y,0);}                                                                 }         } } int started = 0 ;// false; int highestY = 1000; int lowestY = 0; int count=0; int firstX = 0; char letter; char strcount[30]; char totalPath[50]; gdImagePtr arrNewCaptchas[9]; for(x=0;x<width;++x){         int hasblack = 0;// = false;         for(y=0;y<height;++y){                 if(gdImageGetPixel(captcha,x,y) != 0){                                                 if(!started){                                                              started = 1;                                                              firstX = x;                                                              }                                                 hasblack = 1;                                                 if(y < highestY){highestY = y;}                                                 if(y > lowestY) { lowestY = y;}                                                    }                 }         if((started==1) && (hasblack == 0)){      		gdImagePtr newCaptcha = gdImageCreate(x-firstX,lowestY - highestY);			gdImageCopy(newCaptcha,captcha,0,0,firstX,highestY,x-firstX,lowestY-highestY);            arrNewCaptchas[count] = newCaptcha;			if(train == 1){                     printf("Character #%d:\n",count+1);                     letter=getchar();                     sprintf(strcount,"");                     while(letter != '\n') {                                                     sprintf(strcount,"%s%c",strcount,letter);                                   letter= getchar();                      }                      sprintf(strcount,"C:\\delicious-captcha\\\%s.png",strcount);                      //sprintf(totalPath,"delicious-captcha/%s.png",strcount);                      fp = fopen(strcount,"wb");                      gdImagePng(newCaptcha,fp);                          fclose(fp);                     }                         count++;                         started = 0;   } } printf("%d letters extracted\n",count); fp = fopen("delicious.png","wb"); gdImagePng(captcha,fp); fclose(fp); gdImageDestroy(captcha); //now = now_ - now; system("PAUSE"); return 0;}int getPopularity(int x, int y,gdImagePtr captcha){    int popularity =0;    if(gdImageGetPixel(captcha,x+1,y) != 0){ popularity++; }    if(gdImageGetPixel(captcha,x-1,y) != 0){ popularity++; }    if(gdImageGetPixel(captcha,x,y+1) != 0){ popularity++; }    if(gdImageGetPixel(captcha,x,y-1) != 0){ popularity++; }    if(gdImageGetPixel(captcha,x+1,y+1) != 0){ popularity++; }    if(gdImageGetPixel(captcha,x+1,y-1) != 0){ popularity++; }    if(gdImageGetPixel(captcha,x-1,y+1) != 0){ popularity++; }    if(gdImageGetPixel(captcha,x-1,y-1) != 0){ popularity++; }    return popularity;}