pyxllib 0.3.197__py3-none-any.whl → 0.3.200__py3-none-any.whl
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.
- pyxllib/__init__.py +21 -21
- pyxllib/algo/__init__.py +8 -8
- pyxllib/algo/disjoint.py +54 -54
- pyxllib/algo/geo.py +541 -541
- pyxllib/algo/intervals.py +964 -964
- pyxllib/algo/matcher.py +389 -389
- pyxllib/algo/newbie.py +166 -166
- pyxllib/algo/pupil.py +629 -629
- pyxllib/algo/shapelylib.py +67 -67
- pyxllib/algo/specialist.py +241 -241
- pyxllib/algo/stat.py +494 -494
- pyxllib/algo/treelib.py +149 -149
- pyxllib/algo/unitlib.py +66 -66
- pyxllib/autogui/__init__.py +5 -5
- pyxllib/autogui/activewin.py +246 -246
- pyxllib/autogui/all.py +9 -9
- pyxllib/autogui/autogui.py +852 -852
- pyxllib/autogui/uiautolib.py +362 -362
- pyxllib/autogui/virtualkey.py +102 -102
- pyxllib/autogui/wechat.py +827 -827
- pyxllib/autogui/wechat_msg.py +421 -421
- pyxllib/autogui/wxautolib.py +84 -84
- pyxllib/cv/__init__.py +5 -5
- pyxllib/cv/expert.py +267 -267
- pyxllib/cv/imfile.py +159 -159
- pyxllib/cv/imhash.py +39 -39
- pyxllib/cv/pupil.py +9 -9
- pyxllib/cv/rgbfmt.py +1525 -1525
- pyxllib/cv/slidercaptcha.py +137 -137
- pyxllib/cv/trackbartools.py +251 -251
- pyxllib/cv/xlcvlib.py +1040 -1040
- pyxllib/cv/xlpillib.py +423 -423
- pyxllib/data/echarts.py +240 -240
- pyxllib/data/jsonlib.py +89 -89
- pyxllib/data/oss.py +72 -72
- pyxllib/data/pglib.py +1127 -1127
- pyxllib/data/sqlite.py +568 -568
- pyxllib/data/sqllib.py +297 -297
- pyxllib/ext/JLineViewer.py +505 -505
- pyxllib/ext/__init__.py +6 -6
- pyxllib/ext/demolib.py +246 -246
- pyxllib/ext/drissionlib.py +277 -277
- pyxllib/ext/kq5034lib.py +12 -12
- pyxllib/ext/old.py +663 -663
- pyxllib/ext/qt.py +449 -449
- pyxllib/ext/robustprocfile.py +497 -497
- pyxllib/ext/seleniumlib.py +76 -76
- pyxllib/ext/tk.py +173 -173
- pyxllib/ext/unixlib.py +827 -827
- pyxllib/ext/utools.py +351 -351
- pyxllib/ext/webhook.py +124 -119
- pyxllib/ext/win32lib.py +40 -40
- pyxllib/ext/wjxlib.py +88 -88
- pyxllib/ext/wpsapi.py +124 -124
- pyxllib/ext/xlwork.py +9 -9
- pyxllib/ext/yuquelib.py +1105 -1105
- pyxllib/file/__init__.py +17 -17
- pyxllib/file/docxlib.py +761 -761
- pyxllib/file/gitlib.py +309 -309
- pyxllib/file/libreoffice.py +165 -165
- pyxllib/file/movielib.py +148 -148
- pyxllib/file/newbie.py +10 -10
- pyxllib/file/onenotelib.py +1469 -1469
- pyxllib/file/packlib/__init__.py +330 -330
- pyxllib/file/packlib/zipfile.py +2441 -2441
- pyxllib/file/pdflib.py +426 -426
- pyxllib/file/pupil.py +185 -185
- pyxllib/file/specialist/__init__.py +685 -685
- pyxllib/file/specialist/dirlib.py +799 -799
- pyxllib/file/specialist/download.py +193 -193
- pyxllib/file/specialist/filelib.py +2829 -2829
- pyxllib/file/xlsxlib.py +3131 -3131
- pyxllib/file/xlsyncfile.py +341 -341
- pyxllib/prog/__init__.py +5 -5
- pyxllib/prog/cachetools.py +64 -64
- pyxllib/prog/deprecatedlib.py +233 -233
- pyxllib/prog/filelock.py +42 -42
- pyxllib/prog/ipyexec.py +253 -253
- pyxllib/prog/multiprogs.py +940 -940
- pyxllib/prog/newbie.py +451 -451
- pyxllib/prog/pupil.py +1197 -1197
- pyxllib/prog/sitepackages.py +33 -33
- pyxllib/prog/specialist/__init__.py +391 -391
- pyxllib/prog/specialist/bc.py +203 -203
- pyxllib/prog/specialist/browser.py +497 -497
- pyxllib/prog/specialist/common.py +347 -347
- pyxllib/prog/specialist/datetime.py +198 -198
- pyxllib/prog/specialist/tictoc.py +240 -240
- pyxllib/prog/specialist/xllog.py +180 -180
- pyxllib/prog/xlosenv.py +108 -108
- pyxllib/stdlib/__init__.py +17 -17
- pyxllib/stdlib/tablepyxl/__init__.py +10 -10
- pyxllib/stdlib/tablepyxl/style.py +303 -303
- pyxllib/stdlib/tablepyxl/tablepyxl.py +130 -130
- pyxllib/text/__init__.py +8 -8
- pyxllib/text/ahocorasick.py +39 -39
- pyxllib/text/airscript.js +744 -744
- pyxllib/text/charclasslib.py +121 -121
- pyxllib/text/jiebalib.py +267 -267
- pyxllib/text/jinjalib.py +32 -32
- pyxllib/text/jsa_ai_prompt.md +271 -271
- pyxllib/text/jscode.py +922 -922
- pyxllib/text/latex/__init__.py +158 -158
- pyxllib/text/levenshtein.py +303 -303
- pyxllib/text/nestenv.py +1215 -1215
- pyxllib/text/newbie.py +300 -300
- pyxllib/text/pupil/__init__.py +8 -8
- pyxllib/text/pupil/common.py +1121 -1121
- pyxllib/text/pupil/xlalign.py +326 -326
- pyxllib/text/pycode.py +47 -47
- pyxllib/text/specialist/__init__.py +8 -8
- pyxllib/text/specialist/common.py +112 -112
- pyxllib/text/specialist/ptag.py +186 -186
- pyxllib/text/spellchecker.py +172 -172
- pyxllib/text/templates/echart_base.html +10 -10
- pyxllib/text/templates/highlight_code.html +16 -16
- pyxllib/text/templates/latex_editor.html +102 -102
- pyxllib/text/vbacode.py +17 -17
- pyxllib/text/xmllib.py +747 -747
- pyxllib/xl.py +42 -39
- pyxllib/xlcv.py +17 -17
- {pyxllib-0.3.197.dist-info → pyxllib-0.3.200.dist-info}/METADATA +1 -1
- pyxllib-0.3.200.dist-info/RECORD +126 -0
- {pyxllib-0.3.197.dist-info → pyxllib-0.3.200.dist-info}/licenses/LICENSE +190 -190
- pyxllib-0.3.197.dist-info/RECORD +0 -126
- {pyxllib-0.3.197.dist-info → pyxllib-0.3.200.dist-info}/WHEEL +0 -0
pyxllib/cv/imfile.py
CHANGED
@@ -1,159 +1,159 @@
|
|
1
|
-
#!/usr/bin/env python3
|
2
|
-
# -*- coding: utf-8 -*-
|
3
|
-
# @Author : 陈坤泽
|
4
|
-
# @Email : 877362867@qq.com
|
5
|
-
# @Date : 2020/06/02 16:00
|
6
|
-
|
7
|
-
|
8
|
-
from collections import defaultdict
|
9
|
-
import concurrent.futures
|
10
|
-
import os
|
11
|
-
import re
|
12
|
-
import subprocess
|
13
|
-
|
14
|
-
from pyxllib.file.specialist import File
|
15
|
-
|
16
|
-
|
17
|
-
def magick(infile, *, outfile=None, if_exists='error', transparent=None, trim=False, density=None, other_args=None):
|
18
|
-
""" 调用iamge magick的magick.exe工具
|
19
|
-
|
20
|
-
:param infile: 处理对象文件
|
21
|
-
:param outfile: 输出文件,可以不写,默认原地操作(只设置透明度、裁剪时可能会原地操作)
|
22
|
-
:param if_exists: 如果目标文件已存在要怎么处理
|
23
|
-
:param transparent:
|
24
|
-
True: 将白底设置为透明底
|
25
|
-
可以传入颜色参数,控制要设置的为透明底的背景色,默认为'white'
|
26
|
-
注意也可以设置rgb:'rgb(164,192,167)'
|
27
|
-
:param trim: 裁剪掉四周空白
|
28
|
-
:param density: 设置图片的dpi值
|
29
|
-
:param other_args: 其他参数,输入格式如:['-quality', 100]
|
30
|
-
:return:
|
31
|
-
False:infile不存在或者不支持的文件扩展名
|
32
|
-
返回生成的文件名(outfile)
|
33
|
-
"""
|
34
|
-
# 1 条件判断,有些情况下不用处理
|
35
|
-
if not outfile:
|
36
|
-
outfile = infile
|
37
|
-
|
38
|
-
# 2
|
39
|
-
# 200914周一20:40,这有个相对路径的bug,修复了下,否则 test/a.png 会变成 test/test/a.png
|
40
|
-
if File(outfile).exist_preprcs(if_exists):
|
41
|
-
# 2.1 判断是否是支持的输入文件类型
|
42
|
-
ext = os.path.splitext(infile)[1].lower()
|
43
|
-
if not File(infile) or not ext in ('.png', '.eps', '.pdf', '.jpg', '.jpeg', '.wmf', '.emf'):
|
44
|
-
return False
|
45
|
-
|
46
|
-
# 2.2 生成需要执行的参数
|
47
|
-
cmd = ['magick.exe']
|
48
|
-
# 透明、裁剪、density都是可以重复操作的
|
49
|
-
if density: cmd.extend(['-density', str(density)])
|
50
|
-
cmd.append(infile)
|
51
|
-
if transparent:
|
52
|
-
if not isinstance(transparent, str):
|
53
|
-
transparent_ = 'white'
|
54
|
-
else:
|
55
|
-
transparent_ = transparent
|
56
|
-
cmd.extend(['-transparent', transparent_])
|
57
|
-
if trim: cmd.append('-trim')
|
58
|
-
if other_args: cmd.extend(other_args)
|
59
|
-
cmd.append(outfile)
|
60
|
-
|
61
|
-
# 2.3 生成目标png图片
|
62
|
-
cmd = [x.replace('\\', '/') for x in cmd]
|
63
|
-
print(' '.join(cmd))
|
64
|
-
subprocess.run(cmd, stderr=subprocess.PIPE, shell=True) # 看不懂magick出错写的是啥,关了
|
65
|
-
|
66
|
-
return outfile
|
67
|
-
|
68
|
-
|
69
|
-
def ensure_pngs(folder, *, if_exists='skip',
|
70
|
-
transparent=None, trim=False,
|
71
|
-
density=None, epsdensity=None,
|
72
|
-
max_workers=None):
|
73
|
-
""" 确保一个目录下的所有图片都有一个png版本格式的文件
|
74
|
-
|
75
|
-
:param folder: 目录名,会遍历直接目录下所有没png的stem名称生成png
|
76
|
-
:param if_exists: 如果文件已存在,要进行的操作
|
77
|
-
'replace',直接替换
|
78
|
-
'backup',备份后生成新文件
|
79
|
-
'ignore',不写入
|
80
|
-
|
81
|
-
:param transparent: 设置转换后的图片是否要变透明
|
82
|
-
:param trim: 是否裁剪边缘空白
|
83
|
-
:param density: 缩放尺寸
|
84
|
-
TODO magick 和 inkscape 的dpi参考值是不同的,inkscape是真的dpi,magick有个比例差,我还没搞明白
|
85
|
-
:param epsdensity: eps转png时默认放大的比例,注意默认100%是72,写144等于长宽各放大一倍
|
86
|
-
:param max_workers: 并行的最大线程数
|
87
|
-
"""
|
88
|
-
|
89
|
-
# 1 提取字典d,key<str>: 文件stem名称, value<set>:含有的扩展名
|
90
|
-
d = defaultdict(set)
|
91
|
-
for file in os.listdir(folder):
|
92
|
-
if file.endswith('-eps-converted-to.pdf'): continue
|
93
|
-
name, ext = os.path.splitext(file)
|
94
|
-
ext = ext.lower()
|
95
|
-
if ext in ('.png', '.eps', '.pdf', '.jpg', '.jpeg', '.wmf', '.emf', '.svg'):
|
96
|
-
d[name].add(ext)
|
97
|
-
|
98
|
-
# 2 遍历处理每个stem的图片
|
99
|
-
executor = concurrent.futures.ThreadPoolExecutor(max_workers)
|
100
|
-
for name, exts in d.items():
|
101
|
-
# 已经存在png格式的图片时,看if_exists参数
|
102
|
-
if '.png' in exts:
|
103
|
-
if if_exists == 'ignore':
|
104
|
-
continue
|
105
|
-
elif if_exists == 'backup':
|
106
|
-
File(name, folder, suffix='.png').backup(move=True)
|
107
|
-
elif if_exists == 'replace':
|
108
|
-
pass
|
109
|
-
else:
|
110
|
-
raise ValueError
|
111
|
-
|
112
|
-
# 注意这里必须按照指定的类型优先级顺序,找到母图后替换,不能用找到的文件类型顺序
|
113
|
-
for t in ('.eps', '.pdf', '.jpg', '.jpeg', '.wmf', '.emf', '.svg'):
|
114
|
-
if t in exts:
|
115
|
-
filename = os.path.join(folder, name)
|
116
|
-
if t == '.svg': # svg用inkscape软件单独处理
|
117
|
-
cmd = ['inkscape.exe', '-f', filename + t] # 使用inkscape把svg转png
|
118
|
-
if trim: cmd.append('-D') # 裁剪参数
|
119
|
-
if density: cmd.extend(['-d', str(density)]) # 设置dpi参数
|
120
|
-
cmd.extend(['-e', filename + '.png'])
|
121
|
-
executor.submit(subprocess.run, cmd)
|
122
|
-
elif t == '.eps':
|
123
|
-
executor.submit(magick, filename + t, outfile=filename + '.png',
|
124
|
-
transparent=transparent, trim=trim, density=epsdensity)
|
125
|
-
else:
|
126
|
-
executor.submit(magick, filename + t, outfile=filename + '.png',
|
127
|
-
transparent=transparent, trim=trim, density=density)
|
128
|
-
break
|
129
|
-
executor.shutdown()
|
130
|
-
|
131
|
-
|
132
|
-
def zoomsvg(file, scale=1):
|
133
|
-
""" 缩放svg文件
|
134
|
-
|
135
|
-
:param file:
|
136
|
-
如果输入一个目录,会处理目录下所有的svg图片
|
137
|
-
否则只处理指定的文件
|
138
|
-
如果是文本文件,则处理完文本后返回
|
139
|
-
:param scale: 缩放的比例,默认100%不调整
|
140
|
-
:return:
|
141
|
-
"""
|
142
|
-
if scale == 1: return
|
143
|
-
|
144
|
-
def func(m):
|
145
|
-
def g(m): return m.group(1) + str(float(m.group(2)) * scale)
|
146
|
-
|
147
|
-
return re.sub(r'((?:height|width)=")(\d+(?:\.\d+)?)', g, m.group())
|
148
|
-
|
149
|
-
if os.path.isfile(file):
|
150
|
-
s = re.sub(r'<svg .+?>', func, File(file).read(), flags=re.DOTALL)
|
151
|
-
File(file).write(s, if_exists='replace')
|
152
|
-
elif os.path.isdir(file):
|
153
|
-
for f in os.listdir(file):
|
154
|
-
if not f.endswith('.svg'): continue
|
155
|
-
f = os.path.join(file, f)
|
156
|
-
s = re.sub(r'<svg\s+.+?>', func, File(f).read(), flags=re.DOTALL)
|
157
|
-
File(file).write(s, if_exists='replace')
|
158
|
-
elif isinstance(file, str) and '<svg ' in file: # 输入svg的代码文本
|
159
|
-
return re.sub(r'<svg .+?>', func, file, flags=re.DOTALL)
|
1
|
+
#!/usr/bin/env python3
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
# @Author : 陈坤泽
|
4
|
+
# @Email : 877362867@qq.com
|
5
|
+
# @Date : 2020/06/02 16:00
|
6
|
+
|
7
|
+
|
8
|
+
from collections import defaultdict
|
9
|
+
import concurrent.futures
|
10
|
+
import os
|
11
|
+
import re
|
12
|
+
import subprocess
|
13
|
+
|
14
|
+
from pyxllib.file.specialist import File
|
15
|
+
|
16
|
+
|
17
|
+
def magick(infile, *, outfile=None, if_exists='error', transparent=None, trim=False, density=None, other_args=None):
|
18
|
+
""" 调用iamge magick的magick.exe工具
|
19
|
+
|
20
|
+
:param infile: 处理对象文件
|
21
|
+
:param outfile: 输出文件,可以不写,默认原地操作(只设置透明度、裁剪时可能会原地操作)
|
22
|
+
:param if_exists: 如果目标文件已存在要怎么处理
|
23
|
+
:param transparent:
|
24
|
+
True: 将白底设置为透明底
|
25
|
+
可以传入颜色参数,控制要设置的为透明底的背景色,默认为'white'
|
26
|
+
注意也可以设置rgb:'rgb(164,192,167)'
|
27
|
+
:param trim: 裁剪掉四周空白
|
28
|
+
:param density: 设置图片的dpi值
|
29
|
+
:param other_args: 其他参数,输入格式如:['-quality', 100]
|
30
|
+
:return:
|
31
|
+
False:infile不存在或者不支持的文件扩展名
|
32
|
+
返回生成的文件名(outfile)
|
33
|
+
"""
|
34
|
+
# 1 条件判断,有些情况下不用处理
|
35
|
+
if not outfile:
|
36
|
+
outfile = infile
|
37
|
+
|
38
|
+
# 2
|
39
|
+
# 200914周一20:40,这有个相对路径的bug,修复了下,否则 test/a.png 会变成 test/test/a.png
|
40
|
+
if File(outfile).exist_preprcs(if_exists):
|
41
|
+
# 2.1 判断是否是支持的输入文件类型
|
42
|
+
ext = os.path.splitext(infile)[1].lower()
|
43
|
+
if not File(infile) or not ext in ('.png', '.eps', '.pdf', '.jpg', '.jpeg', '.wmf', '.emf'):
|
44
|
+
return False
|
45
|
+
|
46
|
+
# 2.2 生成需要执行的参数
|
47
|
+
cmd = ['magick.exe']
|
48
|
+
# 透明、裁剪、density都是可以重复操作的
|
49
|
+
if density: cmd.extend(['-density', str(density)])
|
50
|
+
cmd.append(infile)
|
51
|
+
if transparent:
|
52
|
+
if not isinstance(transparent, str):
|
53
|
+
transparent_ = 'white'
|
54
|
+
else:
|
55
|
+
transparent_ = transparent
|
56
|
+
cmd.extend(['-transparent', transparent_])
|
57
|
+
if trim: cmd.append('-trim')
|
58
|
+
if other_args: cmd.extend(other_args)
|
59
|
+
cmd.append(outfile)
|
60
|
+
|
61
|
+
# 2.3 生成目标png图片
|
62
|
+
cmd = [x.replace('\\', '/') for x in cmd]
|
63
|
+
print(' '.join(cmd))
|
64
|
+
subprocess.run(cmd, stderr=subprocess.PIPE, shell=True) # 看不懂magick出错写的是啥,关了
|
65
|
+
|
66
|
+
return outfile
|
67
|
+
|
68
|
+
|
69
|
+
def ensure_pngs(folder, *, if_exists='skip',
|
70
|
+
transparent=None, trim=False,
|
71
|
+
density=None, epsdensity=None,
|
72
|
+
max_workers=None):
|
73
|
+
""" 确保一个目录下的所有图片都有一个png版本格式的文件
|
74
|
+
|
75
|
+
:param folder: 目录名,会遍历直接目录下所有没png的stem名称生成png
|
76
|
+
:param if_exists: 如果文件已存在,要进行的操作
|
77
|
+
'replace',直接替换
|
78
|
+
'backup',备份后生成新文件
|
79
|
+
'ignore',不写入
|
80
|
+
|
81
|
+
:param transparent: 设置转换后的图片是否要变透明
|
82
|
+
:param trim: 是否裁剪边缘空白
|
83
|
+
:param density: 缩放尺寸
|
84
|
+
TODO magick 和 inkscape 的dpi参考值是不同的,inkscape是真的dpi,magick有个比例差,我还没搞明白
|
85
|
+
:param epsdensity: eps转png时默认放大的比例,注意默认100%是72,写144等于长宽各放大一倍
|
86
|
+
:param max_workers: 并行的最大线程数
|
87
|
+
"""
|
88
|
+
|
89
|
+
# 1 提取字典d,key<str>: 文件stem名称, value<set>:含有的扩展名
|
90
|
+
d = defaultdict(set)
|
91
|
+
for file in os.listdir(folder):
|
92
|
+
if file.endswith('-eps-converted-to.pdf'): continue
|
93
|
+
name, ext = os.path.splitext(file)
|
94
|
+
ext = ext.lower()
|
95
|
+
if ext in ('.png', '.eps', '.pdf', '.jpg', '.jpeg', '.wmf', '.emf', '.svg'):
|
96
|
+
d[name].add(ext)
|
97
|
+
|
98
|
+
# 2 遍历处理每个stem的图片
|
99
|
+
executor = concurrent.futures.ThreadPoolExecutor(max_workers)
|
100
|
+
for name, exts in d.items():
|
101
|
+
# 已经存在png格式的图片时,看if_exists参数
|
102
|
+
if '.png' in exts:
|
103
|
+
if if_exists == 'ignore':
|
104
|
+
continue
|
105
|
+
elif if_exists == 'backup':
|
106
|
+
File(name, folder, suffix='.png').backup(move=True)
|
107
|
+
elif if_exists == 'replace':
|
108
|
+
pass
|
109
|
+
else:
|
110
|
+
raise ValueError
|
111
|
+
|
112
|
+
# 注意这里必须按照指定的类型优先级顺序,找到母图后替换,不能用找到的文件类型顺序
|
113
|
+
for t in ('.eps', '.pdf', '.jpg', '.jpeg', '.wmf', '.emf', '.svg'):
|
114
|
+
if t in exts:
|
115
|
+
filename = os.path.join(folder, name)
|
116
|
+
if t == '.svg': # svg用inkscape软件单独处理
|
117
|
+
cmd = ['inkscape.exe', '-f', filename + t] # 使用inkscape把svg转png
|
118
|
+
if trim: cmd.append('-D') # 裁剪参数
|
119
|
+
if density: cmd.extend(['-d', str(density)]) # 设置dpi参数
|
120
|
+
cmd.extend(['-e', filename + '.png'])
|
121
|
+
executor.submit(subprocess.run, cmd)
|
122
|
+
elif t == '.eps':
|
123
|
+
executor.submit(magick, filename + t, outfile=filename + '.png',
|
124
|
+
transparent=transparent, trim=trim, density=epsdensity)
|
125
|
+
else:
|
126
|
+
executor.submit(magick, filename + t, outfile=filename + '.png',
|
127
|
+
transparent=transparent, trim=trim, density=density)
|
128
|
+
break
|
129
|
+
executor.shutdown()
|
130
|
+
|
131
|
+
|
132
|
+
def zoomsvg(file, scale=1):
|
133
|
+
""" 缩放svg文件
|
134
|
+
|
135
|
+
:param file:
|
136
|
+
如果输入一个目录,会处理目录下所有的svg图片
|
137
|
+
否则只处理指定的文件
|
138
|
+
如果是文本文件,则处理完文本后返回
|
139
|
+
:param scale: 缩放的比例,默认100%不调整
|
140
|
+
:return:
|
141
|
+
"""
|
142
|
+
if scale == 1: return
|
143
|
+
|
144
|
+
def func(m):
|
145
|
+
def g(m): return m.group(1) + str(float(m.group(2)) * scale)
|
146
|
+
|
147
|
+
return re.sub(r'((?:height|width)=")(\d+(?:\.\d+)?)', g, m.group())
|
148
|
+
|
149
|
+
if os.path.isfile(file):
|
150
|
+
s = re.sub(r'<svg .+?>', func, File(file).read(), flags=re.DOTALL)
|
151
|
+
File(file).write(s, if_exists='replace')
|
152
|
+
elif os.path.isdir(file):
|
153
|
+
for f in os.listdir(file):
|
154
|
+
if not f.endswith('.svg'): continue
|
155
|
+
f = os.path.join(file, f)
|
156
|
+
s = re.sub(r'<svg\s+.+?>', func, File(f).read(), flags=re.DOTALL)
|
157
|
+
File(file).write(s, if_exists='replace')
|
158
|
+
elif isinstance(file, str) and '<svg ' in file: # 输入svg的代码文本
|
159
|
+
return re.sub(r'<svg .+?>', func, file, flags=re.DOTALL)
|
pyxllib/cv/imhash.py
CHANGED
@@ -1,39 +1,39 @@
|
|
1
|
-
#!/usr/bin/env python3
|
2
|
-
# -*- coding: utf-8 -*-
|
3
|
-
# @Author : 陈坤泽
|
4
|
-
# @Email : 877362867@qq.com
|
5
|
-
# @Date : 2021/06/08 22:53
|
6
|
-
|
7
|
-
"""
|
8
|
-
TODO 写一些图片相似度相关功能
|
9
|
-
"""
|
10
|
-
|
11
|
-
from pyxllib.prog.pupil import check_install_package
|
12
|
-
|
13
|
-
check_install_package('imagehash', 'ImageHash')
|
14
|
-
|
15
|
-
import imagehash
|
16
|
-
import numpy as np
|
17
|
-
|
18
|
-
from pyxllib.cv.xlpillib import xlpil
|
19
|
-
|
20
|
-
|
21
|
-
def get_init_hash():
|
22
|
-
""" 获得一个初始、空哈希值 """
|
23
|
-
return imagehash.ImageHash(np.zeros([8, 8]).astype(bool))
|
24
|
-
|
25
|
-
|
26
|
-
def phash(image, *args, **kwargs):
|
27
|
-
""" 修改了官方接口,这里输入的image支持泛用格式
|
28
|
-
"""
|
29
|
-
im = xlpil.read(image)
|
30
|
-
return imagehash.phash(im, *args, **kwargs)
|
31
|
-
|
32
|
-
|
33
|
-
def dhash(image, *args, **kwargs):
|
34
|
-
""" 修改了官方接口,这里输入的image支持泛用格式
|
35
|
-
|
36
|
-
官方比较推荐使用,性能速度又快的,就是dhash
|
37
|
-
"""
|
38
|
-
im = xlpil.read(image)
|
39
|
-
return imagehash.dhash(im, *args, **kwargs)
|
1
|
+
#!/usr/bin/env python3
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
# @Author : 陈坤泽
|
4
|
+
# @Email : 877362867@qq.com
|
5
|
+
# @Date : 2021/06/08 22:53
|
6
|
+
|
7
|
+
"""
|
8
|
+
TODO 写一些图片相似度相关功能
|
9
|
+
"""
|
10
|
+
|
11
|
+
from pyxllib.prog.pupil import check_install_package
|
12
|
+
|
13
|
+
check_install_package('imagehash', 'ImageHash')
|
14
|
+
|
15
|
+
import imagehash
|
16
|
+
import numpy as np
|
17
|
+
|
18
|
+
from pyxllib.cv.xlpillib import xlpil
|
19
|
+
|
20
|
+
|
21
|
+
def get_init_hash():
|
22
|
+
""" 获得一个初始、空哈希值 """
|
23
|
+
return imagehash.ImageHash(np.zeros([8, 8]).astype(bool))
|
24
|
+
|
25
|
+
|
26
|
+
def phash(image, *args, **kwargs):
|
27
|
+
""" 修改了官方接口,这里输入的image支持泛用格式
|
28
|
+
"""
|
29
|
+
im = xlpil.read(image)
|
30
|
+
return imagehash.phash(im, *args, **kwargs)
|
31
|
+
|
32
|
+
|
33
|
+
def dhash(image, *args, **kwargs):
|
34
|
+
""" 修改了官方接口,这里输入的image支持泛用格式
|
35
|
+
|
36
|
+
官方比较推荐使用,性能速度又快的,就是dhash
|
37
|
+
"""
|
38
|
+
im = xlpil.read(image)
|
39
|
+
return imagehash.dhash(im, *args, **kwargs)
|
pyxllib/cv/pupil.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
#!/usr/bin/env python3
|
2
|
-
# -*- coding: utf-8 -*-
|
3
|
-
# @Author : 陈坤泽
|
4
|
-
# @Email : 877362867@qq.com
|
5
|
-
# @Date : 2021/10/07 09:06
|
6
|
-
|
7
|
-
# Rgb用了numpy,不再属于pupil了,而且会初始化很多颜色列表,也浪费空间,
|
8
|
-
# 所以改成独立包,需要的时候再手动导入
|
9
|
-
# from pyxllib.cv.rgbfmt import RgbFormatter
|
1
|
+
#!/usr/bin/env python3
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
# @Author : 陈坤泽
|
4
|
+
# @Email : 877362867@qq.com
|
5
|
+
# @Date : 2021/10/07 09:06
|
6
|
+
|
7
|
+
# Rgb用了numpy,不再属于pupil了,而且会初始化很多颜色列表,也浪费空间,
|
8
|
+
# 所以改成独立包,需要的时候再手动导入
|
9
|
+
# from pyxllib.cv.rgbfmt import RgbFormatter
|