Skip to content

Commit

Permalink
fix: add open sans fony as defuat font
Browse files Browse the repository at this point in the history
  • Loading branch information
aboutmydreams committed Sep 24, 2024
1 parent 7caf321 commit 69d7ef0
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 18 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ name, img = pycapt.do_captcha(
num_of_str=4,
font=30,
gray_value=255,
font_family='ヒラギノ角ゴシック W8.ttc'
font_family=None
)

print(name)
Expand Down Expand Up @@ -233,7 +233,7 @@ filename, img = pycapt.easy_train_img(
noise_N=0.3,
noise_Z=2,
gray_value=255,
font_family='ヒラギノ角ゴシック W8.ttc'
font_family=None
)
```

Expand Down
4 changes: 2 additions & 2 deletions README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ name,img = pycapt.do_captcha(
num_of_str=4,
font=30,
gray_value=255,
font_family='ヒラギノ角ゴシック W8.ttc')
font_family=None)

print(name)
img.show()
Expand Down Expand Up @@ -250,7 +250,7 @@ filename,img = pycapt.easy_train_img(
noise_N=0.3,
noise_Z=2,
gray_value=255,
font_family='ヒラギノ角ゴシック W8.ttc')
font_family=None)
```

只要你再写一个循环,**img.save('train_img/{}.png'.format(file_name))** 就可以生成成千上万张训练集图片 获取标签只需要 name = file_name[0] 就可以惹。
Expand Down
Binary file added pycapt/make_captcha/OpenSans-Bold.ttf
Binary file not shown.
6 changes: 3 additions & 3 deletions pycapt/make_captcha/easy_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def make_capt_img(
height,
num_of_str,
gray_value=255,
font_family="ヒラギノ角ゴシック W8.ttc",
font_family="OpenSans-Bold.ttf",
):
str_list, image = mk_captcha(
my_str_list, width, height, num_of_str, gray_value, font_family
Expand Down Expand Up @@ -66,7 +66,7 @@ def easy_train_img(
noise_N=0.3,
noise_Z=2,
gray_value=255,
font_family="ヒラギノ角ゴシック W8.ttc",
font_family="OpenSans-Bold.ttf",
):
char_list, image = do_captcha(
my_str_list, width, height, num_of_str, font, gray_value, font_family
Expand Down Expand Up @@ -105,7 +105,7 @@ def do_captcha(
num_of_str,
font=30,
gray_value=255,
font_family="ヒラギノ角ゴシック W8.ttc",
font_family="OpenSans-Bold.ttf",
):
"""生成验证码。"""
return mk_captcha(
Expand Down
6 changes: 3 additions & 3 deletions pycapt/make_captcha/make_capt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import numpy as np
import random
import time
import os


# 随机字母:
Expand All @@ -30,9 +31,8 @@ def get_captcha(width, height, num_of_str, gray_value=255):
image = Image.new("RGB", (width, height), (255, 255, 255))

# 创建Font对象:
font = ImageFont.truetype(
"ヒラギノ角ゴシック W8.ttc", 31
) # '/Library/Fonts/Bodoni 72.ttc'
current_dir = os.path.dirname(os.path.abspath(__file__))
font = ImageFont.truetype(f"{current_dir}/OpenSans-Bold.ttf", 31)

# 创建Draw对象:
draw = ImageDraw.Draw(image)
Expand Down
14 changes: 9 additions & 5 deletions pycapt/make_captcha/my_any_img.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from PIL import Image, ImageDraw, ImageFont
import random
import os


# 随机字母:
Expand Down Expand Up @@ -29,14 +30,17 @@ def mk_captcha(
num_of_str,
font=30,
gray_value=255,
font_family="ヒラギノ角ゴシック W8.ttc",
font_family=None,
):
image = Image.new("RGB", (width, height), (255, 255, 255))

# 创建Font对象:
font = ImageFont.truetype(
font_family, font
) # '/Library/Fonts/Bodoni 72.ttc' 'ヒラギノ角ゴシック W8.ttc'
if font_family is None or font_family == "OpenSans-Bold.ttf":
# 创建Font对象:
current_dir = os.path.dirname(os.path.abspath(__file__))
font = ImageFont.truetype(f"{current_dir}/OpenSans-Bold.ttf", 31)
else:
font = ImageFont.truetype(font_family, font)

# 创建Draw对象:
draw = ImageDraw.Draw(image)
Expand All @@ -61,6 +65,6 @@ def mk_captcha(


### 测试
# a,b = mk_captcha(['A','B','1','2','3','4'],160,40,4)
# a, b = mk_captcha(["A", "B", "1", "2", "3", "4"], 160, 40, 4)
# print(a)
# b.show()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="pycapt",
version="1.0.17",
version="1.0.18",
author="aboutmydreams",
author_email="[email protected]",
description="a library that processes verification codes",
Expand Down
4 changes: 2 additions & 2 deletions tests/test_train_img.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_generate_captcha_image(self):
num_of_str=4,
font=30,
gray_value=255,
font_family="ヒラギノ角ゴシック W8.ttc",
font_family="OpenSans-Bold.ttf",
)
img.save(self.image_path) # Save the generated image

Expand Down Expand Up @@ -57,7 +57,7 @@ def test_generate_training_image(self):
noise_N=0.3,
noise_Z=2,
gray_value=255,
font_family="ヒラギノ角ゴシック W8.ttc",
font_family="OpenSans-Bold.ttf",
)
img.save(self.train_image_path) # Save the generated training image

Expand Down

0 comments on commit 69d7ef0

Please sign in to comment.