rucaptcha 2.0.0.beta3 → 2.0.0.beta4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f92a176b27e156909683cc97c9c218b642f6d82e
4
- data.tar.gz: 7e3661aaad88123af8d173bb9772d7c3789510ce
3
+ metadata.gz: abeea0fd2c1d23218c330e3ff7452b3b9906d6b4
4
+ data.tar.gz: f9b5ff05abf6034537d7076ff3c16b968372455c
5
5
  SHA512:
6
- metadata.gz: 7353880dcc6d05db34cf8bc8337321727300e1adffbb5dbdca8bc58c0cfd47e1f0741c9bd6794720a3748b6f45196b6079044471eb638b3ac280d715d56adccf
7
- data.tar.gz: a802c98fa2e84e02b27a716c431382dcc5b246f17b7ea975486e1c75fc34390639b4de3b3eecf389244f61fe451083f4b991095ff700e133b1d8441811608ae6
6
+ metadata.gz: d9e5ed41b6c855ced136802a1117e9b9a22ad1838d2e8eb1e5ba049bba2580a5b1497bd0bae9202028fe306b629807806b065d44997913764114a3f41a3e8710
7
+ data.tar.gz: a0a6e2411fb7bae88685ab07f24b74d177d8838170fb4d106c28f0718c3fd759f8b64d85745a2957142a7cf55db4e1476fdc6fa47f1833bbb660e13c270203e5
data/README.md CHANGED
@@ -4,44 +4,20 @@
4
4
  [![Build Status](https://travis-ci.org/huacnlee/rucaptcha.svg)](https://travis-ci.org/huacnlee/rucaptcha)
5
5
  [![Code Climate](https://codeclimate.com/github/huacnlee/rucaptcha/badges/gpa.svg)](https://codeclimate.com/github/huacnlee/rucaptcha)
6
6
 
7
- This is a Captcha gem for Rails Applications. It runs an ImageMagick command to draw Captcha image - so it has NO performance issues or memory leak issues. **There is NO: RMagick**
7
+ This is a Captcha gem for Rails Applications. It drawing captcha image with C extension.
8
8
 
9
9
  ## Example
10
10
 
11
- ![1](https://cloud.githubusercontent.com/assets/5518/15423974/b186b0d6-1eb2-11e6-9c0e-4cc3a66f32c8.png)
12
- ![2](https://cloud.githubusercontent.com/assets/5518/15423975/b1887b6e-1eb2-11e6-895f-5629f82697d3.png)
13
- ![3](https://cloud.githubusercontent.com/assets/5518/15423978/b18f08ee-1eb2-11e6-9670-c21dba290e04.png)
14
- ![4](https://cloud.githubusercontent.com/assets/5518/15423976/b18b6946-1eb2-11e6-8413-700ded157262.png)
15
- ![5](https://cloud.githubusercontent.com/assets/5518/15423977/b18e7c62-1eb2-11e6-96f7-5bd6981d4185.png)
16
- ![6](https://cloud.githubusercontent.com/assets/5518/15423979/b19175d4-1eb2-11e6-9417-7d496fb996b4.png)
17
- ![7](https://cloud.githubusercontent.com/assets/5518/15423980/b1caf944-1eb2-11e6-862e-78c0a9360b43.png)
18
-
19
- Idea by: https://ruby-china.org/topics/20558#reply4
11
+ <img src="https://cloud.githubusercontent.com/assets/5518/22151425/e02390c8-df58-11e6-974d-5eb9b1a4e577.gif" width="150px" /> <img src="https://cloud.githubusercontent.com/assets/5518/22151427/e4939d92-df58-11e6-9754-4a46a86acea8.gif" width="150px" /> <img src="https://cloud.githubusercontent.com/assets/5518/22151431/e494576e-df58-11e6-9845-a5590904c175.gif" width="150px" /> <img src="https://cloud.githubusercontent.com/assets/5518/22151432/e495066e-df58-11e6-92b8-38b40b73aba0.gif" width="150px" /> <img src="https://cloud.githubusercontent.com/assets/5518/22151428/e49404ee-df58-11e6-8e2d-8b17b33a3710.gif" width="150px" /> <img src="https://cloud.githubusercontent.com/assets/5518/22151430/e4942406-df58-11e6-9ff8-6e2325304b41.gif" width="150px" /> <img src="https://cloud.githubusercontent.com/assets/5518/22151429/e4941ae2-df58-11e6-8107-757296573b2f.gif" width="150px" /> <img src="https://cloud.githubusercontent.com/assets/5518/22151433/e4c7c89c-df58-11e6-9853-1ffbb4986962.gif" width="150px" /> <img src="https://cloud.githubusercontent.com/assets/5518/22151435/e4c97ea8-df58-11e6-8959-b4c78716271d.gif" width="150px" /> <img src="https://cloud.githubusercontent.com/assets/5518/22151436/e4cc09f2-df58-11e6-965c-673333b33c0d.gif" width="150px" /> <img src="https://cloud.githubusercontent.com/assets/5518/22151434/e4c87788-df58-11e6-9490-c255aaafce71.gif" width="150px" /> <img src="https://cloud.githubusercontent.com/assets/5518/22151445/ee35ff66-df58-11e6-8660-a3673ef3f5ee.gif" width="150px" /> <img src="https://cloud.githubusercontent.com/assets/5518/22151446/ee67b074-df58-11e6-9b95-7d53eec21c33.gif" width="150px" />
20
12
 
21
13
  [中文介绍和使用说明](https://ruby-china.org/topics/27832)
22
14
 
23
15
  ## Feature
24
16
 
25
- - Only need `ImageMagick`, No `RMagick`, No `mini_magick`;
17
+ - No dependencies. No ImageMagick, No RMagick.
26
18
  - For Rails Application;
27
19
  - Simple, Easy to use;
28
- - File Caching for performance.
29
-
30
- ## Requirements
31
-
32
- - ImageMagick 6.9+
33
-
34
- #### Ubuntu
35
-
36
- ```
37
- sudo apt-get install imagemagick ghostscript
38
- ```
39
-
40
- #### Mac OS X
41
-
42
- ```bash
43
- brew install imagemagick ghostscript
44
- ```
20
+ - High performance.
45
21
 
46
22
  ## Usage
47
23
 
@@ -90,7 +66,7 @@ class AccountController < ApplicationController
90
66
  end
91
67
  ```
92
68
 
93
- > TIP: Sometime you may need keep last verified captcha code in session on `verify_rucaptcha?` method call, you can use `keep_session: true`. For example: ` Verify_rucaptcha? (@user, keep_session: true) `.
69
+ > TIP: Sometime you may need keep last verified captcha code in session on `verify_rucaptcha?` method call, you can use `keep_session: true`. For example: `verify_rucaptcha? @user, keep_session: true`.
94
70
 
95
71
  View `app/views/account/new.html.erb`
96
72
 
@@ -0,0 +1,345 @@
1
+ // Colors from
2
+ // https://material.io/guidelines/style/color.html#color-ui-color-palette
3
+ static char *colors[] = {
4
+ // Black 500 #000000
5
+ "GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
6
+ "\x00\x00\x00"
7
+ "\x00\x00\x00"
8
+ "\x00\x00\x00"
9
+ "\x00\x00\x00"
10
+ "\x00\x00\x00"
11
+ "\x00\x00\x00"
12
+ "\x00\x00\x00"
13
+ "\x00\x00\x00"
14
+ "\x00\x00\x00"
15
+ "\x00\x00\x00"
16
+ "\x00\x00\x00"
17
+ "\x00\x00\x00"
18
+ "\x00\x00\x00"
19
+ "\x00\x00\x00"
20
+ "\x00\x00\x00"
21
+ "\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",
22
+
23
+ // Red 500 #F44336
24
+ "GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
25
+ "\xF4\x43\x36"
26
+ "\xF4\x43\x36"
27
+ "\xF4\x43\x36"
28
+ "\xF4\x43\x36"
29
+ "\xF4\x43\x36"
30
+ "\xF4\x43\x36"
31
+ "\xF4\x43\x36"
32
+ "\xF4\x43\x36"
33
+ "\xF4\x43\x36"
34
+ "\xF4\x43\x36"
35
+ "\xF4\x43\x36"
36
+ "\xF4\x43\x36"
37
+ "\xF4\x43\x36"
38
+ "\xF4\x43\x36"
39
+ "\xF4\x43\x36"
40
+ "\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",
41
+
42
+ // Pink 500 #E91E63
43
+ "GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
44
+ "\xE9\x1E\x63"
45
+ "\xE9\x1E\x63"
46
+ "\xE9\x1E\x63"
47
+ "\xE9\x1E\x63"
48
+ "\xE9\x1E\x63"
49
+ "\xE9\x1E\x63"
50
+ "\xE9\x1E\x63"
51
+ "\xE9\x1E\x63"
52
+ "\xE9\x1E\x63"
53
+ "\xE9\x1E\x63"
54
+ "\xE9\x1E\x63"
55
+ "\xE9\x1E\x63"
56
+ "\xE9\x1E\x63"
57
+ "\xE9\x1E\x63"
58
+ "\xE9\x1E\x63"
59
+ "\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",
60
+
61
+ // Purple 500 #9C27B0
62
+ "GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
63
+ "\x9C\x27\xB0"
64
+ "\x9C\x27\xB0"
65
+ "\x9C\x27\xB0"
66
+ "\x9C\x27\xB0"
67
+ "\x9C\x27\xB0"
68
+ "\x9C\x27\xB0"
69
+ "\x9C\x27\xB0"
70
+ "\x9C\x27\xB0"
71
+ "\x9C\x27\xB0"
72
+ "\x9C\x27\xB0"
73
+ "\x9C\x27\xB0"
74
+ "\x9C\x27\xB0"
75
+ "\x9C\x27\xB0"
76
+ "\x9C\x27\xB0"
77
+ "\x9C\x27\xB0"
78
+ "\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",
79
+
80
+ // Deep Purple 500 #673AB7
81
+ "GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
82
+ "\x67\x3A\xB7"
83
+ "\x67\x3A\xB7"
84
+ "\x67\x3A\xB7"
85
+ "\x67\x3A\xB7"
86
+ "\x67\x3A\xB7"
87
+ "\x67\x3A\xB7"
88
+ "\x67\x3A\xB7"
89
+ "\x67\x3A\xB7"
90
+ "\x67\x3A\xB7"
91
+ "\x67\x3A\xB7"
92
+ "\x67\x3A\xB7"
93
+ "\x67\x3A\xB7"
94
+ "\x67\x3A\xB7"
95
+ "\x67\x3A\xB7"
96
+ "\x67\x3A\xB7"
97
+ "\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",
98
+
99
+ // Indigo 500 #3F51B5
100
+ "GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
101
+ "\x3F\x51\xB5"
102
+ "\x3F\x51\xB5"
103
+ "\x3F\x51\xB5"
104
+ "\x3F\x51\xB5"
105
+ "\x3F\x51\xB5"
106
+ "\x3F\x51\xB5"
107
+ "\x3F\x51\xB5"
108
+ "\x3F\x51\xB5"
109
+ "\x3F\x51\xB5"
110
+ "\x3F\x51\xB5"
111
+ "\x3F\x51\xB5"
112
+ "\x3F\x51\xB5"
113
+ "\x3F\x51\xB5"
114
+ "\x3F\x51\xB5"
115
+ "\x3F\x51\xB5"
116
+ "\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",
117
+
118
+ // Blue 500 #2196F3
119
+ "GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
120
+ "\x21\x96\xF3"
121
+ "\x21\x96\xF3"
122
+ "\x21\x96\xF3"
123
+ "\x21\x96\xF3"
124
+ "\x21\x96\xF3"
125
+ "\x21\x96\xF3"
126
+ "\x21\x96\xF3"
127
+ "\x21\x96\xF3"
128
+ "\x21\x96\xF3"
129
+ "\x21\x96\xF3"
130
+ "\x21\x96\xF3"
131
+ "\x21\x96\xF3"
132
+ "\x21\x96\xF3"
133
+ "\x21\x96\xF3"
134
+ "\x21\x96\xF3"
135
+ "\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",
136
+
137
+ // Light Blue 500 #03A9F4
138
+ "GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
139
+ "\x03\xA9\xF4"
140
+ "\x03\xA9\xF4"
141
+ "\x03\xA9\xF4"
142
+ "\x03\xA9\xF4"
143
+ "\x03\xA9\xF4"
144
+ "\x03\xA9\xF4"
145
+ "\x03\xA9\xF4"
146
+ "\x03\xA9\xF4"
147
+ "\x03\xA9\xF4"
148
+ "\x03\xA9\xF4"
149
+ "\x03\xA9\xF4"
150
+ "\x03\xA9\xF4"
151
+ "\x03\xA9\xF4"
152
+ "\x03\xA9\xF4"
153
+ "\x03\xA9\xF4"
154
+ "\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",
155
+
156
+ // Cyan 500 #00BCD4
157
+ "GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
158
+ "\x00\xBC\xD4"
159
+ "\x00\xBC\xD4"
160
+ "\x00\xBC\xD4"
161
+ "\x00\xBC\xD4"
162
+ "\x00\xBC\xD4"
163
+ "\x00\xBC\xD4"
164
+ "\x00\xBC\xD4"
165
+ "\x00\xBC\xD4"
166
+ "\x00\xBC\xD4"
167
+ "\x00\xBC\xD4"
168
+ "\x00\xBC\xD4"
169
+ "\x00\xBC\xD4"
170
+ "\x00\xBC\xD4"
171
+ "\x00\xBC\xD4"
172
+ "\x00\xBC\xD4"
173
+ "\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",
174
+
175
+ // Teal 500 #009688
176
+ "GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
177
+ "\x00\x96\x88"
178
+ "\x00\x96\x88"
179
+ "\x00\x96\x88"
180
+ "\x00\x96\x88"
181
+ "\x00\x96\x88"
182
+ "\x00\x96\x88"
183
+ "\x00\x96\x88"
184
+ "\x00\x96\x88"
185
+ "\x00\x96\x88"
186
+ "\x00\x96\x88"
187
+ "\x00\x96\x88"
188
+ "\x00\x96\x88"
189
+ "\x00\x96\x88"
190
+ "\x00\x96\x88"
191
+ "\x00\x96\x88"
192
+ "\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",
193
+
194
+ // Green 500 #4CAF50
195
+ "GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
196
+ "\x4C\xAF\x50"
197
+ "\x4C\xAF\x50"
198
+ "\x4C\xAF\x50"
199
+ "\x4C\xAF\x50"
200
+ "\x4C\xAF\x50"
201
+ "\x4C\xAF\x50"
202
+ "\x4C\xAF\x50"
203
+ "\x4C\xAF\x50"
204
+ "\x4C\xAF\x50"
205
+ "\x4C\xAF\x50"
206
+ "\x4C\xAF\x50"
207
+ "\x4C\xAF\x50"
208
+ "\x4C\xAF\x50"
209
+ "\x4C\xAF\x50"
210
+ "\x4C\xAF\x50"
211
+ "\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",
212
+
213
+ // Light Green 500 #8BC34A
214
+ "GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
215
+ "\x8B\xC3\x4A"
216
+ "\x8B\xC3\x4A"
217
+ "\x8B\xC3\x4A"
218
+ "\x8B\xC3\x4A"
219
+ "\x8B\xC3\x4A"
220
+ "\x8B\xC3\x4A"
221
+ "\x8B\xC3\x4A"
222
+ "\x8B\xC3\x4A"
223
+ "\x8B\xC3\x4A"
224
+ "\x8B\xC3\x4A"
225
+ "\x8B\xC3\x4A"
226
+ "\x8B\xC3\x4A"
227
+ "\x8B\xC3\x4A"
228
+ "\x8B\xC3\x4A"
229
+ "\x8B\xC3\x4A"
230
+ "\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",
231
+
232
+ // Lime 500 #CDDC39
233
+ "GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
234
+ "\xCD\xDC\x39"
235
+ "\xCD\xDC\x39"
236
+ "\xCD\xDC\x39"
237
+ "\xCD\xDC\x39"
238
+ "\xCD\xDC\x39"
239
+ "\xCD\xDC\x39"
240
+ "\xCD\xDC\x39"
241
+ "\xCD\xDC\x39"
242
+ "\xCD\xDC\x39"
243
+ "\xCD\xDC\x39"
244
+ "\xCD\xDC\x39"
245
+ "\xCD\xDC\x39"
246
+ "\xCD\xDC\x39"
247
+ "\xCD\xDC\x39"
248
+ "\xCD\xDC\x39"
249
+ "\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",
250
+
251
+ // Yellow 500 #FFEB3B
252
+ "GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
253
+ "\xFF\xEB\x3B"
254
+ "\xFF\xEB\x3B"
255
+ "\xFF\xEB\x3B"
256
+ "\xFF\xEB\x3B"
257
+ "\xFF\xEB\x3B"
258
+ "\xFF\xEB\x3B"
259
+ "\xFF\xEB\x3B"
260
+ "\xFF\xEB\x3B"
261
+ "\xFF\xEB\x3B"
262
+ "\xFF\xEB\x3B"
263
+ "\xFF\xEB\x3B"
264
+ "\xFF\xEB\x3B"
265
+ "\xFF\xEB\x3B"
266
+ "\xFF\xEB\x3B"
267
+ "\xFF\xEB\x3B"
268
+ "\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",
269
+
270
+ // Amber 500 #FFC107
271
+ "GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
272
+ "\xFF\xC1\x07"
273
+ "\xFF\xC1\x07"
274
+ "\xFF\xC1\x07"
275
+ "\xFF\xC1\x07"
276
+ "\xFF\xC1\x07"
277
+ "\xFF\xC1\x07"
278
+ "\xFF\xC1\x07"
279
+ "\xFF\xC1\x07"
280
+ "\xFF\xC1\x07"
281
+ "\xFF\xC1\x07"
282
+ "\xFF\xC1\x07"
283
+ "\xFF\xC1\x07"
284
+ "\xFF\xC1\x07"
285
+ "\xFF\xC1\x07"
286
+ "\xFF\xC1\x07"
287
+ "\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",
288
+
289
+ // Orange 500 #FF9800
290
+ "GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
291
+ "\xFF\x98\x00"
292
+ "\xFF\x98\x00"
293
+ "\xFF\x98\x00"
294
+ "\xFF\x98\x00"
295
+ "\xFF\x98\x00"
296
+ "\xFF\x98\x00"
297
+ "\xFF\x98\x00"
298
+ "\xFF\x98\x00"
299
+ "\xFF\x98\x00"
300
+ "\xFF\x98\x00"
301
+ "\xFF\x98\x00"
302
+ "\xFF\x98\x00"
303
+ "\xFF\x98\x00"
304
+ "\xFF\x98\x00"
305
+ "\xFF\x98\x00"
306
+ "\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",
307
+
308
+ // Deep Orange 500 #FF5722
309
+ "GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
310
+ "\xFF\x57\x22"
311
+ "\xFF\x57\x22"
312
+ "\xFF\x57\x22"
313
+ "\xFF\x57\x22"
314
+ "\xFF\x57\x22"
315
+ "\xFF\x57\x22"
316
+ "\xFF\x57\x22"
317
+ "\xFF\x57\x22"
318
+ "\xFF\x57\x22"
319
+ "\xFF\x57\x22"
320
+ "\xFF\x57\x22"
321
+ "\xFF\x57\x22"
322
+ "\xFF\x57\x22"
323
+ "\xFF\x57\x22"
324
+ "\xFF\x57\x22"
325
+ "\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",
326
+
327
+ // Brown 500 #795548
328
+ "GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
329
+ "\x79\x55\x48"
330
+ "\x79\x55\x48"
331
+ "\x79\x55\x48"
332
+ "\x79\x55\x48"
333
+ "\x79\x55\x48"
334
+ "\x79\x55\x48"
335
+ "\x79\x55\x48"
336
+ "\x79\x55\x48"
337
+ "\x79\x55\x48"
338
+ "\x79\x55\x48"
339
+ "\x79\x55\x48"
340
+ "\x79\x55\x48"
341
+ "\x79\x55\x48"
342
+ "\x79\x55\x48"
343
+ "\x79\x55\x48"
344
+ "\xff\xff\xff" "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04"
345
+ };
@@ -5,58 +5,47 @@ void makegif(unsigned char im[70*200], unsigned char gif[gifsize]);
5
5
 
6
6
  #include <unistd.h>
7
7
  #include <stdint.h>
8
+ #include <stdlib.h>
8
9
  #include <fcntl.h>
9
10
  #include <string.h>
11
+ #include <time.h>
10
12
  #include <ruby.h>
11
13
  #include "font.h"
14
+ #include "colors.h"
12
15
 
13
16
  static int8_t *lt[];
14
17
  const int gifsize=17646;
15
18
 
16
19
  void makegif(unsigned char im[70*200], unsigned char gif[gifsize]) {
17
- // tag ; widthxheight ; GCT:0:0:7 ; bgcolor + aspect // GCT
18
- // Image Separator // left x top // widthxheight // Flags
19
- // LZW code size
20
- memcpy(gif,"GIF89a" "\xc8\0\x46\0" "\x83" "\0\0"
21
- "\x00\x00\x00"
22
- "\x10\x10\x10"
23
- "\x20\x20\x20"
24
- "\x30\x30\x30"
25
- "\x40\x40\x40"
26
- "\x50\x50\x50"
27
- "\x60\x60\x60"
28
- "\x70\x70\x70"
29
- "\x80\x80\x80"
30
- "\x90\x90\x90"
31
- "\xa0\xa0\xa0"
32
- "\xb0\xb0\xb0"
33
- "\xc0\xc0\xc0"
34
- "\xd0\xd0\xd0"
35
- "\xe0\xe0\xe0"
36
- "\xff\xff\xff"
37
- "," "\0\0\0\0" "\xc8\0\x46\0" "\0" "\x04",13+48+10+1);
38
-
39
- int x,y;
40
- unsigned char *i=im;
41
- unsigned char *p=gif+13+48+10+1;
42
- for(y=0;y<70;y++) {
43
- *p++=250; // Data length 5*50=250
44
- for(x=0;x<50;x++)
45
- {
46
- unsigned char a=i[0]>>4,b=i[1]>>4,c=i[2]>>4,d=i[3]>>4;
47
-
48
- p[0]=16|(a<<5); // bbb10000
49
- p[1]=(a>>3)|64|(b<<7); // b10000xb
50
- p[2]=b>>1; // 0000xbbb
51
- p[3]=1|(c<<1); // 00xbbbb1
52
- p[4]=4|(d<<3); // xbbbb100
53
- i+=4;
54
- p+=5;
55
- }
56
- }
57
-
58
- // Data length // End of LZW (b10001) // Terminator // GIF End
59
- memcpy(gif+gifsize-4,"\x01" "\x11" "\x00" ";",4);
20
+ // tag ; widthxheight ; GCT:0:0:7 ; bgcolor + aspect // GCT
21
+ // Image Separator // left x top // widthxheight // Flags
22
+ // LZW code size
23
+ srand(time(NULL));
24
+ int color_len = (int) sizeof(colors) / sizeof(colors[0]);
25
+ int color_idx = rand() % color_len;
26
+ memcpy(gif,colors[color_idx],13+48+10+1);
27
+
28
+ int x,y;
29
+ unsigned char *i=im;
30
+ unsigned char *p=gif+13+48+10+1;
31
+ for(y=0;y<70;y++) {
32
+ *p++=250; // Data length 5*50=250
33
+ for(x=0;x<50;x++)
34
+ {
35
+ unsigned char a=i[0]>>4,b=i[1]>>4,c=i[2]>>4,d=i[3]>>4;
36
+
37
+ p[0]=16|(a<<5); // bbb10000
38
+ p[1]=(a>>3)|64|(b<<7); // b10000xb
39
+ p[2]=b>>1; // 0000xbbb
40
+ p[3]=1|(c<<1); // 00xbbbb1
41
+ p[4]=4|(d<<3); // xbbbb100
42
+ i+=4;
43
+ p+=5;
44
+ }
45
+ }
46
+
47
+ // Data length // End of LZW (b10001) // Terminator // GIF End
48
+ memcpy(gif+gifsize-4,"\x01" "\x11" "\x00" ";",4);
60
49
  }
61
50
 
62
51
  static const int8_t sw[200]={0, 4, 8, 12, 16, 20, 23, 27, 31, 35, 39, 43, 47, 50, 54, 58, 61, 65, 68, 71, 75, 78, 81, 84, 87, 90, 93, 96, 98, 101, 103, 105, 108, 110, 112, 114, 115, 117, 119, 120, 121, 122, 123, 124, 125, 126, 126, 127, 127, 127, 127, 127, 127, 127, 126, 126, 125, 124, 123, 122, 121, 120, 119, 117, 115, 114, 112, 110, 108, 105, 103, 101, 98, 96, 93, 90, 87, 84, 81, 78, 75, 71, 68, 65, 61, 58, 54, 50, 47, 43, 39, 35, 31, 27, 23, 20, 16, 12, 8, 4, 0, -4, -8, -12, -16, -20, -23, -27, -31, -35, -39, -43, -47, -50, -54, -58, -61, -65, -68, -71, -75, -78, -81, -84, -87, -90, -93, -96, -98, -101, -103, -105, -108, -110, -112, -114, -115, -117, -119, -120, -121, -122, -123, -124, -125, -126, -126, -127, -127, -127, -127, -127, -127, -127, -126, -126, -125, -124, -123, -122, -121, -120, -119, -117, -115, -114, -112, -110, -108, -105, -103, -101, -98, -96, -93, -90, -87, -84, -81, -78, -75, -71, -68, -65, -61, -58, -54, -50, -47, -43, -39, -35, -31, -27, -23, -20, -16, -12, -8, -4};
@@ -65,35 +54,35 @@ static const int8_t sw[200]={0, 4, 8, 12, 16, 20, 23, 27, 31, 35, 39, 43, 47, 50
65
54
  #define MAX(x,y) ((x>y)?(x):(y))
66
55
 
67
56
  static int letter(int n, int pos, unsigned char im[70*200], unsigned char swr[200], uint8_t s1, uint8_t s2) {
68
- int8_t *p=lt[n];
69
- unsigned char *r=im+200*16+pos;
70
- unsigned char *i=r;
71
- int sk1=s1+pos;
72
- int sk2=s2+pos;
73
- int mpos=pos;
74
- int row=0;
75
- for(;*p!=-101;p++) {
76
- if(*p<0) {
77
- if(*p==-100) { r+=200; i=r; sk1=s1+pos; row++; continue; }
78
- i+=-*p;
79
- continue;
80
- }
81
-
82
- if(sk1>=200) sk1=sk1%200;
83
- int skew=sw[sk1]/16;
84
- sk1+=(swr[pos+i-r]&0x1)+1;
85
-
86
- if(sk2>=200) sk2=sk2%200;
87
- int skewh=sw[sk2]/70;
88
- sk2+=(swr[row]&0x1);
89
-
90
- unsigned char *x=i+skew*200+skewh;
91
- mpos=MAX(mpos,pos+i-r);
92
-
93
- if((x-im)<70*200) *x=(*p)<<4;
94
- i++;
95
- }
96
- return mpos;
57
+ int8_t *p=lt[n];
58
+ unsigned char *r=im+200*16+pos;
59
+ unsigned char *i=r;
60
+ int sk1=s1+pos;
61
+ int sk2=s2+pos;
62
+ int mpos=pos;
63
+ int row=0;
64
+ for(;*p!=-101;p++) {
65
+ if(*p<0) {
66
+ if(*p==-100) { r+=200; i=r; sk1=s1+pos; row++; continue; }
67
+ i+=-*p;
68
+ continue;
69
+ }
70
+
71
+ if(sk1>=200) sk1=sk1%200;
72
+ int skew=sw[sk1]/16;
73
+ sk1+=(swr[pos+i-r]&0x1)+1;
74
+
75
+ if(sk2>=200) sk2=sk2%200;
76
+ int skewh=sw[sk2]/70;
77
+ sk2+=(swr[row]&0x1);
78
+
79
+ unsigned char *x=i+skew*200+skewh;
80
+ mpos=MAX(mpos,pos+i-r);
81
+
82
+ if((x-im)<70*200) *x=(*p)<<4;
83
+ i++;
84
+ }
85
+ return mpos;
97
86
  }
98
87
 
99
88
  #define NDOTS 100
@@ -101,77 +90,77 @@ static int letter(int n, int pos, unsigned char im[70*200], unsigned char swr[20
101
90
  uint32_t dr[NDOTS];
102
91
 
103
92
  static void line(unsigned char im[70*200], unsigned char swr[200], uint8_t s1) {
104
- int x;
105
- int sk1=s1;
106
- for(x=0;x<199;x++) {
107
- if(sk1>=200) sk1=sk1%200;
108
- int skew=sw[sk1]/16;
109
- sk1+=swr[x]&0x3+1;
110
- unsigned char *i= im+(200*(45+skew)+x);
111
- i[0]=0; i[1]=0; i[200]=0; i[201]=0;
112
- }
93
+ int x;
94
+ int sk1=s1;
95
+ for(x=0;x<199;x++) {
96
+ if(sk1>=200) sk1=sk1%200;
97
+ int skew=sw[sk1]/16;
98
+ sk1+=swr[x]&0x3+1;
99
+ unsigned char *i= im+(200*(45+skew)+x);
100
+ i[0]=0; i[1]=0; i[200]=0; i[201]=0;
101
+ }
113
102
  }
114
103
 
115
104
  static void dots(unsigned char im[70*200]) {
116
- int n;
117
- for(n=0;n<NDOTS;n++) {
118
- uint32_t v=dr[n];
119
- unsigned char *i=im+v%(200*67);
120
-
121
- i[0]=0xff;
122
- i[1]=0xff;
123
- i[2]=0xff;
124
- i[200]=0xff;
125
- i[201]=0xff;
126
- i[202]=0xff;
127
- }
105
+ int n;
106
+ for(n=0;n<NDOTS;n++) {
107
+ uint32_t v=dr[n];
108
+ unsigned char *i=im+v%(200*67);
109
+
110
+ i[0]=0xff;
111
+ i[1]=0xff;
112
+ i[2]=0xff;
113
+ i[200]=0xff;
114
+ i[201]=0xff;
115
+ i[202]=0xff;
116
+ }
128
117
  }
129
118
  static void blur(unsigned char im[70*200]) {
130
- unsigned char *i=im;
131
- int x,y;
132
- for(y=0;y<68;y++) {
133
- for(x=0;x<198;x++) {
134
- unsigned int c11=*i,c12=i[1],c21=i[200],c22=i[201];
135
- *i++=((c11+c12+c21+c22)/4);
136
- }
137
- }
119
+ unsigned char *i=im;
120
+ int x,y;
121
+ for(y=0;y<68;y++) {
122
+ for(x=0;x<198;x++) {
123
+ unsigned int c11=*i,c12=i[1],c21=i[200],c22=i[201];
124
+ *i++=((c11+c12+c21+c22)/4);
125
+ }
126
+ }
138
127
  }
139
128
 
140
129
  static void filter(unsigned char im[70*200]) {
141
- unsigned char om[70*200];
142
- unsigned char *i=im;
143
- unsigned char *o=om;
130
+ unsigned char om[70*200];
131
+ unsigned char *i=im;
132
+ unsigned char *o=om;
144
133
 
145
- memset(om,0xff,sizeof(om));
134
+ memset(om,0xff,sizeof(om));
146
135
 
147
- int x,y;
148
- for(y=0;y<70;y++) {
149
- for(x=4;x<200-4;x++) {
150
- if(i[0]>0xf0 && i[1]<0xf0) { o[0]=0; o[1]=0; }
151
- else if(i[0]<0xf0 && i[1]>0xf0) { o[0]=0; o[1]=0; }
136
+ int x,y;
137
+ for(y=0;y<70;y++) {
138
+ for(x=4;x<200-4;x++) {
139
+ if(i[0]>0xf0 && i[1]<0xf0) { o[0]=0; o[1]=0; }
140
+ else if(i[0]<0xf0 && i[1]>0xf0) { o[0]=0; o[1]=0; }
152
141
 
153
- i++;
154
- o++;
155
- }
156
- }
142
+ i++;
143
+ o++;
144
+ }
145
+ }
157
146
 
158
- memmove(im,om,sizeof(om));
147
+ memmove(im,om,sizeof(om));
159
148
  }
160
149
 
161
150
  static const char *letters="abcdafahijklmnopqrstuvwxyz";
162
151
 
163
152
  void captcha(unsigned char im[70*200], unsigned char l[6]) {
164
- unsigned char swr[200];
165
- uint8_t s1,s2;
153
+ unsigned char swr[200];
154
+ uint8_t s1,s2;
166
155
 
167
- int f=open("/dev/urandom",O_RDONLY);
168
- read(f,l,5); read(f,swr,200); read(f,dr,sizeof(dr)); read(f,&s1,1); read(f,&s2,1);
169
- close(f);
156
+ int f=open("/dev/urandom",O_RDONLY);
157
+ read(f,l,5); read(f,swr,200); read(f,dr,sizeof(dr)); read(f,&s1,1); read(f,&s2,1);
158
+ close(f);
170
159
 
171
- memset(im,0xff,200*70); s1=s1&0x7f; s2=s2&0x3f; l[0]%=25; l[1]%=25; l[2]%=25; l[3]%=25; l[4]%=25; l[5]=0;
172
- int p=30; p=letter(l[0],p,im,swr,s1,s2); p=letter(l[1],p,im,swr,s1,s2); p=letter(l[2],p,im,swr,s1,s2); p=letter(l[3],p,im,swr,s1,s2); letter(l[4],p,im,swr,s1,s2);
173
- line(im,swr,s1); dots(im); // blur(im); // filter(im);
174
- l[0]=letters[l[0]]; l[1]=letters[l[1]]; l[2]=letters[l[2]]; l[3]=letters[l[3]]; l[4]=letters[l[4]];
160
+ memset(im,0xff,200*70); s1=s1&0x7f; s2=s2&0x3f; l[0]%=25; l[1]%=25; l[2]%=25; l[3]%=25; l[4]%=25; l[5]=0;
161
+ int p=30; p=letter(l[0],p,im,swr,s1,s2); p=letter(l[1],p,im,swr,s1,s2); p=letter(l[2],p,im,swr,s1,s2); p=letter(l[3],p,im,swr,s1,s2); letter(l[4],p,im,swr,s1,s2);
162
+ line(im,swr,s1); dots(im); // blur(im); // filter(im);
163
+ l[0]=letters[l[0]]; l[1]=letters[l[1]]; l[2]=letters[l[2]]; l[3]=letters[l[3]]; l[4]=letters[l[4]];
175
164
  }
176
165
 
177
166
  // #ifdef CAPTCHA
@@ -204,12 +193,12 @@ void Init_rucaptcha() {
204
193
  }
205
194
 
206
195
  VALUE create(VALUE self) {
207
- char l[6];
208
- unsigned char im[80*200];
209
- unsigned char gif[gifsize];
196
+ char l[6];
197
+ unsigned char im[80*200];
198
+ unsigned char gif[gifsize];
210
199
 
211
- captcha(im,l);
212
- makegif(im,gif);
200
+ captcha(im,l);
201
+ makegif(im,gif);
213
202
 
214
203
  VALUE result = rb_ary_new2(2);
215
204
  rb_ary_push(result, rb_str_new2(l));
@@ -1,3 +1,3 @@
1
1
  module RuCaptcha
2
- VERSION = '2.0.0.beta3'
2
+ VERSION = '2.0.0.beta4'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rucaptcha
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.beta3
4
+ version: 2.0.0.beta4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Lee
@@ -53,6 +53,7 @@ files:
53
53
  - config/locales/rucaptcha.zh-CN.yml
54
54
  - config/locales/rucaptcha.zh-TW.yml
55
55
  - config/routes.rb
56
+ - ext/rucaptcha/colors.h
56
57
  - ext/rucaptcha/extconf.rb
57
58
  - ext/rucaptcha/font.h
58
59
  - ext/rucaptcha/rucaptcha.c