一个帮你将图片转为字符图片的模块。
Project description
Imgtoch
一个帮你将图片转为字符图片的模块。
用法:
# coding: utf-8
from imgtoch import makeImage
makeImage(
"源图片路径",
"生成的图片保存路径",
chars = None, # 用于图像的字符表,字符数应大于 1,无需手动按等效灰度值排序
scale = 1, # 缩放比例,0 < scale <= 1,可省略
quality = 80, # 图片保存质量,大于 0 小于等于 100
fontPath = "字体路径", # 可省略
fontSize = 14, # 字体大小,仅指定字体路径时生效,可省略
horzSep = 2, # 字符横向间隔,可省略
vertSep = 2, # 字符纵向间隔,可省略
keepRatio=True, # 是否保持原比例。因字体高宽不一定相等,生成的图片高宽会变形,此项为 True 则抵消变形,可省略
keepSize=False, # 一个字符对应一个像素点,因字符有大小,所以生成的图片尺寸会变化,此项为 True 会将生成的图片缩放至原图尺寸,可省略
)
实例 1:
# coding: utf-8
from imgtoch import makeImage
# 大图片尽量将 scale 设置的小些,否则生成的图片会比较大
# 字体大小 fontSize 也是影响最终生成的图片大小的因素之一
makeImage("1.jpg", "new.jpg", scale=0.2) # 图片 1.jpg 已在当前目录中
实例 2:
# coding: utf-8
from imgtoch import *
# 获取字符'#'的等效灰度值
print(grayscaleOf("#")) # ('#', 170)
# 将给定字符串按等效灰度值排序
print(sortByGrayscale("H oa.:sjv@%^a'"))
# 结果:['H', '@', 'a', '%', 'a', 's', 'j', 'o', 'v', '^', ':', "'", '.', ' ']
# 其中'a'和'%'的等效灰度值应该是相等的所以出现了'%'被夹在两个'a'中间的问题
# 更具体的参数可以看 IDE 提示或者使用 help 函数
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
imgtoch-0.2.3.tar.gz
(6.3 kB
view details)
Built Distribution
File details
Details for the file imgtoch-0.2.3.tar.gz
.
File metadata
- Download URL: imgtoch-0.2.3.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.7.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14672358336f66b381dd831d6b8410e4e398d1bf82af13f0356513f3f4bfbbed |
|
MD5 | 29e3bc565c42f1107438119f6867f58d |
|
BLAKE2b-256 | 322430a8c056707747b8fc3b5690f8887bbfcced1069a8537da3bd0a8480224f |
File details
Details for the file imgtoch-0.2.3-py3-none-any.whl
.
File metadata
- Download URL: imgtoch-0.2.3-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.7.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f43db0ea03eced31417882f0c948f412a14729b57b042d3fb2279a465659b0e7 |
|
MD5 | ea582aebfa17554cb963c860d47ecd76 |
|
BLAKE2b-256 | 196ece96dee99c98b6417d4c9d5309183bfeb5b1a5b7a80efd0b9c9824eb530d |