用pygments和枕头创建代码片段
code2image的Python项目详细描述
用pygments和枕头创建代码片段。
安装
$ pip install code2image
基本用途
$ python examples/shadow.py
这个软件包是为了自动化一些无聊的图像创建过程而开发的。但是 它还有一个脚本,用于一些命令行的乐趣。
$ code2image --help usage: code2image [-h][--kind {simple,shadow,background}][--imagename IMAGENAME][--code CODE][--background BACKGROUND][--font-size FONT_SIZE][--font-name FONT_NAME][--line_pad LINE_PAD][--line-numbers][--shadow-color SHADOW_COLOR][--shadow-dt SHADOW_DT][--offset OFFSET][--blur BLUR][--epilog EPILOG] codefile Create nice code snippets positional arguments: codefile The code file optional arguments: -h, --help show this help message and exit --kind {simple,shadow,background} Change the result --imagename IMAGENAME The output image --code CODE Code background color --background BACKGROUND Image background color --font-size FONT_SIZE font size --font-name FONT_NAME font name --line_pad LINE_PAD line pad --line-numbers line numbers --shadow-color SHADOW_COLOR Shadow color --shadow-dt SHADOW_DT Shadow offset --offset OFFSET Border width --blur BLUR Shadow blur --scale SCALE A scale --epilog EPILOG A epilog
为Instagram创建漂亮的图像:
$ code2image --kind background --scale 1 /pathe/to/code/file
python示例
fromcode2image.clsimportCode2Imagec2i=Code2Image()# load the source code from this filewithopen(__file__)asf:code=f.read()# create the image with highlighted codeimg=c2i.highlight(code)# save the imageimg.save('simple.png')
有关更多信息,请参阅“示例”文件夹。
开发
克隆回购
$ git clone https://github.com/axju/code2image.git
为Linux创建虚拟环境
$ python3 -m venv venv
$ source venv/bin/activate
或为Windows创建虚拟环境
$ python -m venv venv $ venv/Scripts/activate
更新开发工具
$ python -m pip install --upgrade wheel pip setuptools twine tox flake8
安装本地
$ pip install -e .
发布软件包
$ python setup.py sdist bdist_wheel $ twine upload dist/*
运行一些测试
$ flake8 code2image
$ python setup.py test
$ python -m unittest discover -v
$ tox
我不知道为什么,但毒素会失效:(