Trim blank space and make better position. version 0.3.2
This commit is contained in:
parent
29d02cc09f
commit
bd138df5b8
|
@ -1,3 +1,9 @@
|
||||||
|
0.3.2
|
||||||
|
-----
|
||||||
|
|
||||||
|
- Make better render positions;
|
||||||
|
- Trim blank space.
|
||||||
|
|
||||||
0.3.1
|
0.3.1
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ module RuCaptcha
|
||||||
end
|
end
|
||||||
|
|
||||||
def rand_line_top(text_top, font_size)
|
def rand_line_top(text_top, font_size)
|
||||||
text_top + rand(font_size - text_top * 2)
|
text_top + rand(font_size * 0.7).to_i
|
||||||
end
|
end
|
||||||
|
|
||||||
# Create Captcha image by code
|
# Create Captcha image by code
|
||||||
|
@ -23,19 +23,17 @@ module RuCaptcha
|
||||||
all_left = 20
|
all_left = 20
|
||||||
font_size = RuCaptcha.config.font_size
|
font_size = RuCaptcha.config.font_size
|
||||||
full_height = font_size
|
full_height = font_size
|
||||||
full_width = (font_size * chars.size)
|
full_width = font_size * chars.size
|
||||||
size = "#{full_width}x#{full_height}"
|
size = "#{full_width}x#{full_height}"
|
||||||
half_width = full_width / 2
|
half_width = full_width / 2
|
||||||
full_height = full_height
|
full_height = full_height
|
||||||
half_height = full_height / 2
|
half_height = full_height / 2
|
||||||
text_top = 10
|
text_top = 0
|
||||||
text_left = 0 - (font_size * 0.28).to_i
|
text_left = 0 - (font_size * 0.28).to_i
|
||||||
stroke_width = (font_size * 0.08).to_i + 1
|
stroke_width = (font_size * 0.08).to_i + 1
|
||||||
text_width = (full_width / chars.size) + text_left
|
text_width = font_size + text_left
|
||||||
label = "=#{' ' * (chars.size - 1)}="
|
label = "=#{' ' * (chars.size - 1)}="
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
text_opts = []
|
text_opts = []
|
||||||
line_opts = []
|
line_opts = []
|
||||||
chars.each_with_index do |char, i|
|
chars.each_with_index do |char, i|
|
||||||
|
@ -44,8 +42,9 @@ module RuCaptcha
|
||||||
line_color = "rgba(#{rgb.join(',')}, 0.6)"
|
line_color = "rgba(#{rgb.join(',')}, 0.6)"
|
||||||
text_opts << %(-fill '#{text_color}' -draw 'text #{(text_left + text_width) * i + all_left},#{text_top} "#{char}"')
|
text_opts << %(-fill '#{text_color}' -draw 'text #{(text_left + text_width) * i + all_left},#{text_top} "#{char}"')
|
||||||
left_y = rand_line_top(text_top, font_size)
|
left_y = rand_line_top(text_top, font_size)
|
||||||
|
right_x = half_width + (half_width * 0.3).to_i
|
||||||
right_y = rand_line_top(text_top, font_size)
|
right_y = rand_line_top(text_top, font_size)
|
||||||
line_opts << %(-draw 'stroke #{line_color} line #{rand(10)},#{left_y} #{half_width + rand(half_width / 2)},#{right_y}')
|
line_opts << %(-draw 'stroke #{line_color} line #{rand(10)},#{left_y} #{right_x},#{right_y}')
|
||||||
end
|
end
|
||||||
|
|
||||||
command = <<-CODE
|
command = <<-CODE
|
||||||
|
@ -57,8 +56,8 @@ module RuCaptcha
|
||||||
-wave #{rand(2) + 3}x#{rand(2) + 1} \
|
-wave #{rand(2) + 3}x#{rand(2) + 1} \
|
||||||
-rotate #{rand(10) - 5} \
|
-rotate #{rand(10) - 5} \
|
||||||
-gravity NorthWest -sketch 1x10+#{rand(2)} \
|
-gravity NorthWest -sketch 1x10+#{rand(2)} \
|
||||||
-fill white \
|
-fill none \
|
||||||
-implode #{RuCaptcha.config.implode} label:- png:-
|
-implode #{RuCaptcha.config.implode} -trim label:- png:-
|
||||||
CODE
|
CODE
|
||||||
|
|
||||||
command.strip!
|
command.strip!
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
module RuCaptcha
|
module RuCaptcha
|
||||||
VERSION = '0.3.1'
|
VERSION = '0.3.2'
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue