Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
CPP=g++ | ||
LIBGD_HOME=$(HOME)/code/build/libgd | ||
|
||
CXXFLAGS=-I$(LIBGD_HOME)/include | ||
LDFLAGS=-L$(LIBGD_HOME)/lib -lgd | ||
|
||
.PHONY: all | ||
.PHONY: clean | ||
.PHONY: run | ||
|
||
all: ownCAPTCHA | ||
echo "Welcome to ownCAPTCHA" | ||
|
||
clean: | ||
rm ownCAPTCHA | ||
|
||
run: | ||
./ownCAPTCHA | ||
|
||
*.o: *.cpp | ||
$(CPP) -c -g -o $@ $(CXXFLAGS) $< | ||
|
||
ownCAPTCHA: src/main/cpp/main.cpp | ||
$(CPP) -g -o $@ $(CXXFLAGS) $(LDFLAGS) $^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
ownCAPTCHA | ||
========== | ||
CAPTCHA is a common comp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include <gd.h> | ||
#include <string> | ||
#include <stdio.h> | ||
|
||
struct rgb { | ||
rgb(uint8_t red, uint8_t green, uint8_t blue) : r(red), g(green), b(blue) {}; | ||
uint8_t r; | ||
uint8_t g; | ||
uint8_t b; | ||
}; | ||
|
||
class background { | ||
public: | ||
background(int width, int height, rgb rgb) : | ||
_width(width), _height(height), _rgb(rgb) {} | ||
|
||
template<typename T> background* merge(T old) { | ||
this->_img = gdImageCreateTrueColor(_width, _height); | ||
int bg = gdImageColorResolve(_img, _rgb.r, _rgb.g, _rgb.b); | ||
gdImageFill(_img, 0, 0, bg); | ||
return this; | ||
}; | ||
gdImagePtr img() { | ||
return _img; | ||
} | ||
private: | ||
gdImagePtr _img; | ||
int _width; | ||
int _height; | ||
rgb _rgb; | ||
}; | ||
|
||
class text { | ||
public: | ||
text(const std::string& text, const std::string& font, double size, double angle, int x, int y, rgb rgb) : | ||
_text(text), _font(font), _size(size), _angle(angle), _x(x), _y(y), _rgb(rgb) {}; | ||
template<typename T> text* merge(T old) { | ||
this->_img = old->img(); | ||
int brect[8]; | ||
int color = gdImageColorResolve(_img, _rgb.r, _rgb.g, _rgb.b); | ||
gdImageStringFT(_img, &brect[0], | ||
color, const_cast<char*>(_font.c_str()), _size, | ||
_angle, _x, _y, const_cast<char*>(_text.c_str())); | ||
return this; | ||
}; | ||
gdImagePtr img() { | ||
return _img; | ||
} | ||
private: | ||
std::string _text; | ||
std::string _font; | ||
double _size; | ||
double _angle; | ||
int _x; | ||
int _y; | ||
rgb _rgb; | ||
gdImagePtr _img; | ||
}; | ||
|
||
class save { | ||
public: | ||
save(const std::string& filename) : | ||
_filename(filename) {}; | ||
template<typename T> save* merge(T old) { | ||
FILE* f = fopen(_filename.c_str(), "wb"); | ||
gdImagePng(old->img(), f); | ||
fclose(f); | ||
gdImageDestroy(old->img()); | ||
return NULL; | ||
}; | ||
private: | ||
std::string _filename; | ||
}; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <iostream> | ||
|
||
#include "captcha.hpp" | ||
|
||
int main() { | ||
std::cout << "Welcome to ownCAPTCHA" << std::endl; | ||
|
||
background bg(300, 200, rgb(0x00, 0xF0, 0x00)); | ||
text text("Hello", "./au.ttf", 40, 1, 150, 100, rgb(0x00, 0x00, 0xF0)); | ||
save save("background.png"); | ||
save.merge(text.merge(bg.merge(NULL))); | ||
|
||
return 0; | ||
} |
Empty file.