# 欢迎!

如果说你看到了这里,那么有两种可能,要么是为 ImageMagic 而来,要么就是闲逛,不过,这里都欢迎你的到来!

# 获取 ImageMagic

  1. 使用 pip 下载:
pip install ImageMagic
  1. 从源进行构建:

# DOCS

感谢使用 ImageMagic,这是 Python 的第三方库 ImageMagic 的临时文档,请查阅。若在使用过程中有什么问题或是你觉得可以改进的地方,请联系我!

# Image 模块

# word_to_image()

将文本转换成图片

from ImageMagic import Image
Image.word_to_image('这里是你要转成图片的文本','F:/image/1.png',fontPath='F:/ttf/字语时光体.ttf')

# voice_to_word()

识别音频里的内容,使用讯飞的语音转写,你需要去点击这里获取你的 appid 以及 key,支持格式为 WAV, FLAC, OPUS, M4A, MP3

from ImageMagic import Image
appid = ""
key = ""
filepath = "F:/mp3/test.mp3"
audio = Image.Audio(appid,key,filepath)
text = audio.voice_to_word()
print(text)

# audio_to_image()

将音频内容转为图片,同样,你需要去点击这里获取你的 appid 以及 key,支持格式为 WAV, FLAC, OPUS, M4A, MP3

from ImageMagic import Image
appid = ""
key = ""
filepath = "F:/mp3/test.mp3"
Image.audio_to_image(appid,key,filepath,'F:/image/test.png')  #最后一个参数是图片保存地址

# categorize_image()

分类文件夹里的图片,格式包括 jpg, jpeg, png, webp, bmp, tif, tiff, gif, svg, wmf,会在此文件夹下生成以已有文件的后缀为名的新文件夹,并将同类文件复制到里面

from ImageMagic import Image
Image.categorize_image('F:/images') #这里输入你的文件夹路径

# convert()

转换图片格式

from ImageMagic import Image
Image.convert('F:/image/test.png','webp','F:/image/test.webp')  #第一个参数是原文件路径,第二个是转换的格式,第三个是保存路径

# equal_scale_image()

将图片等比例缩小或者放大

from ImageMagic import Image
Image.equal_scale_image('F:/image/test.png','F:/image/save.png',2) #最后一个参数是变化倍数

# customize_image()

自定义修改图片分辨率,若是不输入第三和四个参数,那么将会使用原参数

from ImageMagic import Image
Image.customize_image('F:/image/test.png','F:/image/save.png',1960,1080)

# lbp_image_hash()

哈希局部二值算法计算图片哈希值

from ImageMagic import Image
hash = Image.lbp_image_hash('F:/image/test.png')
print(hash)

# p_image_hash()

感知哈希算法计算图片哈希值

from ImageMagic import Image
hash = Image.p_image_hash('F:/image/test.png')
print(hash)

# pca_image_hash()

主成分分析算法计算图片哈希值

from ImageMagic import Image
hash = Image.pca_image_hash('F:/image/test.png')

# fft_image_hash()

傅里叶变换算法计算哈希值

from ImageMagic import Image
hash = Image.fft_image_hash('F:/image/test.png')

# average_image_hash()

哈希平均算法计算图片哈希值

from ImageMagic import Image
hash = Image.average_image_hash('F:/image/test.png')
print(hash)

# remove_same_images()

删除某目录下相同的图片且每张图片保留一张。
具体实现:通过计算图片的哈希值,相同图片则会被删除。

from ImageMagic import Image
Image.remove_same_images('F:/image')

# Aocr 模块

使用本模块请前往点击这里下载 OCR 引擎

# image_to_text()

识别图像中的文本,参数 filePath:图片路径,lang:图片里的语言,默认中文,可以多语言,例:'chi_sim+eng',timeout: 识别超时时间,默认 0,即无

from ImageMagic import Aocr
text = Aocr.image_to_text('F:/image/test.png')

# image_to_pdf()

将图片转为可搜索的 pdf 文件

from ImageMagic import Aocr
Aocr.image_to_pdf('F:/image/test.png','F:/pdf/test.pdf')

# image_to_hocr()

将图片转为 HOCR

from ImageMagic import Aocr
hocr = Aocr.image_to_hocr('F:/image/test,png')

# image_to_AltoXml()

将图片转为 AltXml

from ImageMagic import Aocr
xml = Aocr.image_to_AltoXml('F:/image/test.png')

# get_image_data()

获取图片详细的数据,包括框、置信度、行号和页码。需要 tesseract 版本 3.05+

from ImageMagic import Aocr
data = Aocr.get_image_data('F:/image/test.png')

# get_image_osd()

获取有关方向和脚本检测的信息

from ImageMagic import Aocr
osd = Aocr.get_image_osd('F:/image/test.png')

# get_image_boxs()

获取图片边界框的估计值

from ImageMagic import Aocr
boxs = Aocr.get_image_boxs('F:/image/test.png')

# check_languages()

获取已安装的语言包

from ImageMagic import Aocr
lang = Aocr.check_languages()
print(lang)

# Welcome to you !

If you see it, there are two possibilities, either for ImageMagic or just hanging out, but you're welcome here!

# Where to get it ?

  1. Download using pip:
pip install ImageMagic
  1. Build from source:source

# DOCS

Thanks for using ImageMagic, which is temporary documentation for Python's third-party library ImageMagic, check it out. If there are any problems during use or what you think can be improved, please contact me!

# Image module

# word_to_image()

Convert text to images

from ImageMagic import Image
Image.word_to_image("Here's the text you want to turn into an image.",'F:/image/1.png',fontPath='F:/ttf/test.ttf')

# voice_to_word()

To identify the content in the audio and use iFLYTEK's voice transcription, you need to go to [click here] (https://console.xfyun.cn/services/lfasr) to get your appid and key, which are supported in WAV, FLAC, OPUS, M4A, MP3.

from ImageMagic import Image
appid = ""
key = ""
filepath = "F:/mp3/test.mp3"
audio = Image.Audio(appid,key,filepath)
text = audio.voice_to_word()
print(text)

# audio_to_image()

To convert audio content to images, you need to go to [click here] (https://console.xfyun.cn/services/lfasr) to get your appid and key, which are supported in WAV, FLAC, OPUS, M4A, MP3.

from ImageMagic import Image
appid = ""
key = ""
filepath = "F:/mp3/test.mp3"
Image.audio_to_image(appid,key,filepath,'F:/image/test.png')  #The last parameter is the address where the image is saved.

# categorize_image()

The images in the category folder, including jpg, jpeg, png, webp, bmp, tif, tiff, gif, svg, wmf, will generate a new folder named with the suffix of the existing file under this folder, and copy the same kind of files into it.

from ImageMagic import Image
Image.categorize_image('F:/images') #Enter your folder path here

# convert()

Convert image format.

from ImageMagic import Image
Image.convert('F:/image/test.png','webp','F:/image/test.webp')  #The first parameter is the path to the original file, the second is the converted format, and the third is the saved path.

# equal_scale_image()

Reduce or enlarge the image at equal scale.

from ImageMagic import Image
Image.equal_scale_image('F:/image/test.png','F:/image/save.png',2) #The last parameter is the multiplier.

# customize_image()

Customize the image resolution, if you do not enter the third and fourth parameters, the original parameters will be used.

from ImageMagic import Image
Image.customize_image('F:/image/test.png','F:/image/save.png',1960,1080)

# lbp_image_hash()

The hash local binary algorithm calculates the image hash value.

from ImageMagic import Image
hash = Image.lbp_image_hash('F:/image/test.png')
print(hash)

# p_image_hash()

The hash awareness algorithm calculates the image hash value.

from ImageMagic import Image
hash = Image.p_image_hash('F:/image/test.png')
print(hash)

# pca_image_hash()

The principal component analysis algorithm calculates the image hash value.

from ImageMagic import Image
hash = Image.pca_image_hash('F:/image/test.png')

# fft_image_hash()

The Fourier transform algorithm computes the hash value.

from ImageMagic import Image
hash = Image.fft_image_hash('F:/image/test.png')

# average_image_hash()

The hash averaging algorithm calculates the image hash value.

from ImageMagic import Image
hash = Image.average_image_hash('F:/image/test.png')
print(hash)

# remove_same_images()

Delete the same images in a directory and keep one image per image.
Implementation: By calculating the hash value of the image, the same image will be deleted.

from ImageMagic import Image
Image.remove_same_images('F:/image')

# Aocr module

To use this module, go to [click here] (https://tesseract-ocr.github.io/tessdoc/Installation.html) to download the OCR engine.

# image_to_text()

Identify text in an image, parameters filePath: image path, lang: language in the image, default Chinese, can be multilingual, for example: 'chi_sim+eng', timeout: recognition timeout, default 0, that is, none.

from ImageMagic import Aocr
text = Aocr.image_to_text('F:/image/test.png')

# image_to_pdf()

Turn images into searchable PDF files.

from ImageMagic import Aocr
Aocr.image_to_pdf('F:/image/test.png','F:/pdf/test.pdf')

# image_to_hocr()

Turn the picture into HOCR.

from ImageMagic import Aocr
hocr = Aocr.image_to_hocr('F:/image/test,png')

# image_to_AltoXml()

Convert the image to AltXml.

from ImageMagic import Aocr
xml = Aocr.image_to_AltoXml('F:/image/test.png')

# get_image_data()

Get detailed data for an image, including boxes, confidence, line numbers, and page numbers. Requires tesseract version 3.05+.

from ImageMagic import Aocr
data = Aocr.get_image_data('F:/image/test.png')

# get_image_osd()

Get information about orientation and script detection.

from ImageMagic import Aocr
osd = Aocr.get_image_osd('F:/image/test.png')

# get_image_boxs()

Gets an estimate of the picture bounding box.

from ImageMagic import Aocr
boxs = Aocr.get_image_boxs('F:/image/test.png')

# check_languages()

Gets the installed language packs.

from ImageMagic import Aocr
lang = Aocr.check_languages()
print(lang)