用pygments和枕头创建代码片段

code2image的Python项目详细描述


https://img.shields.io/pypi/v/code2image.svg

用pygments和枕头创建代码片段。

安装

$ pip install code2image

基本用途

$ python examples/shadow.py
https://raw.githubusercontent.com/axju/code2image/master/examples/shadow.png

这个软件包是为了自动化一些无聊的图像创建过程而开发的。但是 它还有一个脚本,用于一些命令行的乐趣。

$ 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

我不知道为什么,但毒素会失效:(

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java静态对象初始化   java请求的资源上不存在“Accesscontrolalloworigin”头。起源http://localhost:4200因此不允许访问   java i无法通过executor的submit方法处理列表的所有记录   javadoc中的java文档逻辑   java如何使RCPPlugin独立   java使用cobertura插件跳过*测试*   验证Java处理多个可能未知的日期/时间格式   java将JPanel添加到JFrame   BB 7.0中的黑莓Java标签   java动态地向注释处理环境添加类型   java如何将头信息作为键值对传递给使用jersey的rest服务   java使用ImageJ调整图像大小并裁剪图像   为什么Java8的ToIntFunction<t>不扩展函数<t,Integer>   java无法向Jackson ObjectMapper类注册模块   解析如何将此jsonarray解析为字符串或数组java   如何从Java调用具有数值参数的Scala方法   类如何从ColdFusion实现Java接口?   java如何让线程只添加到一个带有同步