rucaptcha 3.0.1-arm64-darwin → 3.1.0-arm64-darwin
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +12 -1
- data/Rakefile +32 -1
- data/app/controllers/ru_captcha/captcha_controller.rb +1 -1
- data/ext/rucaptcha/src/captcha.rs +27 -20
- data/lib/rucaptcha/2.7/rucaptcha.bundle +0 -0
- data/lib/rucaptcha/3.0/rucaptcha.bundle +0 -0
- data/lib/rucaptcha/3.1/rucaptcha.bundle +0 -0
- data/lib/rucaptcha/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bea39cfc2b5f85511c0503a5ad4ed3f2a8a41385d10cb3ecd0cb9afe3a6e5225
|
4
|
+
data.tar.gz: d61ec3c0fca84b63dcb2d70f4eb22aa090742b4f95e5ef9e905b3348e3224f7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07e2090a60b6ac4a390c2cebf689c8012e6723a9c71218bd30703fff93cce574c184b007c597e278072369be0af800c4cc063433e7ab2258b82ab4bc2104b096
|
7
|
+
data.tar.gz: 7bd76be6212cdd3575df82077da48310c8ab63745f954a988f675afb50311769a446e906fef253299225d02f519c797167e070944272bb748de26d2e7c40253e
|
data/README.md
CHANGED
@@ -14,7 +14,7 @@ Captcha Gem for Rails, which generates captcha image by Rust.
|
|
14
14
|
|
15
15
|
## Example
|
16
16
|
|
17
|
-
|
17
|
+
<img src="https://user-images.githubusercontent.com/5518/196329734-fee49f62-050b-44c8-a5a8-7ffdd3c5a3f6.png" height="50" alt="0"> <img src="https://user-images.githubusercontent.com/5518/196329738-64b264a1-e3fb-4804-ac46-0df18fb31d1e.png" height="50" alt="1"> <img src="https://user-images.githubusercontent.com/5518/196329740-e10ded26-ba46-4e9b-93b8-ce30c198f880.png" height="50" alt="2"> <img src="https://user-images.githubusercontent.com/5518/196329743-c7b055b8-b309-4554-8c95-66c5caf4437d.png" height="50" alt="3"> <img src="https://user-images.githubusercontent.com/5518/196329745-eb68f0c3-ccac-4fa3-aa7a-cc4c2caeb41e.png" height="50" alt="4"> <img src="https://user-images.githubusercontent.com/5518/196329746-b15a9f71-262e-4699-87c7-a5561c6caf2c.png" height="50" alt="5"> <img src="https://user-images.githubusercontent.com/5518/196329747-d111a5d3-89a1-487b-989e-5be8059488c2.png" height="50" alt="6"> <img src="https://user-images.githubusercontent.com/5518/196329749-2cb44aa3-8b59-427c-91f3-59566d6de8a5.png" height="50" alt="7"> <img src="https://user-images.githubusercontent.com/5518/196329754-ae64374b-f2e5-44b8-a7f4-3aee1405c193.png" height="50" alt="8"> <img src="https://user-images.githubusercontent.com/5518/196329755-26b88705-bf34-4d32-a4dc-076530582a90.png" height="50" alt="9">
|
18
18
|
|
19
19
|
## Feature
|
20
20
|
|
@@ -162,3 +162,14 @@ else
|
|
162
162
|
render :new
|
163
163
|
end
|
164
164
|
```
|
165
|
+
|
166
|
+
## Performance
|
167
|
+
|
168
|
+
`rake benchmark` to run benchmark test.
|
169
|
+
|
170
|
+
```
|
171
|
+
Warming up --------------------------------------
|
172
|
+
Generate image 51.000 i/100ms
|
173
|
+
Calculating -------------------------------------
|
174
|
+
Generate image 526.350 (± 2.5%) i/s - 2.652k in 5.041681s
|
175
|
+
```
|
data/Rakefile
CHANGED
@@ -29,6 +29,37 @@ task default: :spec
|
|
29
29
|
task :preview do
|
30
30
|
require "rucaptcha"
|
31
31
|
res = RuCaptchaCore.create(5, 5)
|
32
|
-
warn res[0]
|
32
|
+
warn "-------------------------\n#{res[0]}"
|
33
33
|
puts res[1].pack("c*")
|
34
34
|
end
|
35
|
+
|
36
|
+
task :memory do
|
37
|
+
require "rucaptcha"
|
38
|
+
require "memory_profiler"
|
39
|
+
|
40
|
+
RuCaptchaCore.create(5, 5)
|
41
|
+
|
42
|
+
report = MemoryProfiler.report do
|
43
|
+
1000.times do
|
44
|
+
RuCaptchaCore.create(5, 5)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
GC.start
|
49
|
+
report.pretty_print
|
50
|
+
|
51
|
+
puts "------------------------- Result Guide -------------------------"
|
52
|
+
puts "If [Total retained] have any bytes, there will have memory leak."
|
53
|
+
end
|
54
|
+
|
55
|
+
task :benchmark do
|
56
|
+
require "rucaptcha"
|
57
|
+
require "benchmark/ips"
|
58
|
+
|
59
|
+
RuCaptchaCore.create(5, 5)
|
60
|
+
|
61
|
+
Benchmark.ips do |x|
|
62
|
+
x.report("Generate image") { RuCaptchaCore.create(5, 5) }
|
63
|
+
x.compare!
|
64
|
+
end
|
65
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
use image::{ImageBuffer, Rgb};
|
2
|
-
use imageproc::drawing::{draw_cubic_bezier_curve_mut,
|
3
|
-
use imageproc::noise::
|
2
|
+
use imageproc::drawing::{draw_cubic_bezier_curve_mut, draw_text_mut};
|
3
|
+
use imageproc::noise::gaussian_noise_mut;
|
4
4
|
use rand::{thread_rng, Rng};
|
5
5
|
use rusttype::{Font, Scale};
|
6
6
|
use std::io::Cursor;
|
@@ -14,7 +14,12 @@ static BASIC_CHAR: [char; 54] = [
|
|
14
14
|
static FONT_BYTES1: &[u8; 145008] = include_bytes!("../fonts/FuzzyBubbles-Regular.ttf");
|
15
15
|
static FONT_BYTES2: &[u8; 37792] = include_bytes!("../fonts/Handlee-Regular.ttf");
|
16
16
|
|
17
|
-
|
17
|
+
// https://coolors.co/cc0b8f-7c0abe-5700c8-3c2ea4-3d56a8-3fa67e-45bb30-69d003-a0d003-d8db02
|
18
|
+
static COLORS: [(u8, u8, u8); 14] = [
|
19
|
+
(197, 166, 3),
|
20
|
+
(187, 87, 5),
|
21
|
+
(176, 7, 7),
|
22
|
+
(186, 9, 56),
|
18
23
|
(204, 11, 143),
|
19
24
|
(124, 10, 190),
|
20
25
|
(87, 0, 200),
|
@@ -47,7 +52,7 @@ fn get_captcha(len: usize) -> Vec<String> {
|
|
47
52
|
|
48
53
|
#[allow(unused)]
|
49
54
|
fn get_color() -> Rgb<u8> {
|
50
|
-
let rnd = rand_num(COLORS.len());
|
55
|
+
let rnd = rand_num(COLORS.len() - 1);
|
51
56
|
let c = COLORS[rnd];
|
52
57
|
Rgb([c.0, c.1, c.2])
|
53
58
|
}
|
@@ -94,19 +99,28 @@ fn cyclic_write_character(res: &[String], image: &mut ImageBuffer<Rgb<u8>, Vec<u
|
|
94
99
|
} as f32;
|
95
100
|
|
96
101
|
let colors = get_colors(res.len());
|
102
|
+
let line_colors = get_colors(res.len());
|
97
103
|
|
98
104
|
let xscale = scale - rand_num((scale * 0.2) as usize) as f32;
|
99
105
|
let yscale = h as f32 - rand_num((h * 0.2) as usize) as f32;
|
100
106
|
|
107
|
+
// Draw line, ellipse first as background
|
108
|
+
for (i, _) in res.iter().enumerate() {
|
109
|
+
let line_color = line_colors[i];
|
110
|
+
draw_interference_line(1, image, line_color);
|
111
|
+
draw_interference_ellipse(1, image, line_color);
|
112
|
+
}
|
113
|
+
|
114
|
+
// Draw text
|
101
115
|
for (i, _) in res.iter().enumerate() {
|
102
116
|
let text = &res[i];
|
103
117
|
|
104
118
|
let color = colors[i];
|
105
119
|
let font = get_font();
|
106
|
-
let line_color = colors[rand_num(colors.len() - 1)];
|
107
120
|
|
108
121
|
for j in 0..(rand_num(3) + 1) as i32 {
|
109
|
-
|
122
|
+
// Draw text again with offset
|
123
|
+
let offset = j * (rand_num(2) as i32);
|
110
124
|
draw_text_mut(
|
111
125
|
image,
|
112
126
|
color,
|
@@ -120,9 +134,6 @@ fn cyclic_write_character(res: &[String], image: &mut ImageBuffer<Rgb<u8>, Vec<u
|
|
120
134
|
text,
|
121
135
|
);
|
122
136
|
}
|
123
|
-
|
124
|
-
draw_interference_line(1, image, line_color);
|
125
|
-
draw_interference_ellipse(1, image, line_color);
|
126
137
|
}
|
127
138
|
}
|
128
139
|
|
@@ -139,7 +150,7 @@ fn draw_interference_line(num: usize, image: &mut ImageBuffer<Rgb<u8>, Vec<u8>>,
|
|
139
150
|
let ctrl_x = get_next((width / 6) as f32, width / 4 * 3);
|
140
151
|
let ctrl_y = get_next(x1, height - 5);
|
141
152
|
|
142
|
-
let ctrl_x2 = get_next((width /
|
153
|
+
let ctrl_x2 = get_next((width / 12) as f32, width / 12 * 3);
|
143
154
|
let ctrl_y2 = get_next(x1, height - 5);
|
144
155
|
// Randomly draw bezier curves
|
145
156
|
draw_cubic_bezier_curve_mut(
|
@@ -159,10 +170,12 @@ fn draw_interference_ellipse(
|
|
159
170
|
color: Rgb<u8>,
|
160
171
|
) {
|
161
172
|
for _ in 0..num {
|
173
|
+
// max cycle width 20px
|
162
174
|
let w = (10 + rand_num(10)) as i32;
|
163
175
|
let x = rand_num((image.width() - 25) as usize) as i32;
|
164
176
|
let y = rand_num((image.height() - 15) as usize) as i32;
|
165
|
-
|
177
|
+
|
178
|
+
imageproc::drawing::draw_filled_ellipse_mut(image, (x, y), w, w, color);
|
166
179
|
}
|
167
180
|
}
|
168
181
|
|
@@ -182,8 +195,8 @@ impl CaptchaBuilder {
|
|
182
195
|
pub fn new() -> Self {
|
183
196
|
CaptchaBuilder {
|
184
197
|
length: 4,
|
185
|
-
width:
|
186
|
-
height:
|
198
|
+
width: 220,
|
199
|
+
height: 70,
|
187
200
|
complexity: 5,
|
188
201
|
}
|
189
202
|
}
|
@@ -234,15 +247,9 @@ impl CaptchaBuilder {
|
|
234
247
|
((5 * self.complexity) - 5) as u64,
|
235
248
|
);
|
236
249
|
|
237
|
-
salt_and_pepper_noise_mut(
|
238
|
-
&mut image,
|
239
|
-
((0.001 * self.complexity as f64) - 0.001) as f64,
|
240
|
-
(0.8 * self.complexity as f64) as u64,
|
241
|
-
);
|
242
|
-
|
243
250
|
let mut bytes: Vec<u8> = Vec::new();
|
244
251
|
image
|
245
|
-
.write_to(&mut Cursor::new(&mut bytes), image::ImageFormat::
|
252
|
+
.write_to(&mut Cursor::new(&mut bytes), image::ImageFormat::Jpeg)
|
246
253
|
.unwrap();
|
247
254
|
|
248
255
|
Captcha { text, image: bytes }
|
Binary file
|
Binary file
|
Binary file
|
data/lib/rucaptcha/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rucaptcha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0
|
4
|
+
version: 3.1.0
|
5
5
|
platform: arm64-darwin
|
6
6
|
authors:
|
7
7
|
- Jason Lee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|