Create code snippet with pygments and pillow.
Install
$ pip install code2image
Basic uses
$ python examples/shadow.py
This package was developed to automate some boring image creation process. But it has also a script for some command line fun.
$ 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
To create nice images for instagram:
$ code2image --kind background --scale 1 /pathe/to/code/file
Python examples
from code2image.cls import Code2Image
c2i = Code2Image()
# load the source code from this file
with open(__file__) as f:
code = f.read()
# create the image with highlighted code
img = c2i.highlight(code)
# save the image
img.save('simple.png')
See the “examples” folder for more.
Development
Clone repo
$ git clone https://github.com/axju/code2image.git
Create virtual environment for linux
$ python3 -m venv venv
$ source venv/bin/activate
or create virtual environment for windows
$ python -m venv venv
$ venv/Scripts/activate
update dev-tools
$ python -m pip install --upgrade wheel pip setuptools twine tox flake8
Install local
$ pip install -e .
Publish the packages
$ python setup.py sdist bdist_wheel
$ twine upload dist/*
Run some tests
$ flake8 code2image
$ python setup.py test
$ python -m unittest discover -v
$ tox
I do not know why, but tox will fail :(
Metadata
Release files for code2image 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| code2image-0.0.3.tar.gz | 5.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| code2image-0.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.0 kB
Release files / code2image-0.0.3.tar.gz
| Download URL | code2image-0.0.3.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7fff19e988f8d08ace6ab104bd85a0fc213b530a70a768028bc08f1a26870324
|
|
BLAKE2b-256 checksum How to use checksums |
a9985ff1dd36e8962e2bb3efe5baf029fc7a1111c8bda3f9afe86b290ed6e5d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0
|
Release files / code2image-0.0.3-py3-none-any.whl
| Download URL | code2image-0.0.3-py3-none-any.whl |
|---|---|
| Size | 7.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
86c6fcd4edda20abf1d66d5b5a7c48cf18cb2eb90374be9853732c6b8c696b84
|
|
BLAKE2b-256 checksum How to use checksums |
fa6457d2275574a9b36cd3ab51fb1e3fccf121f98cca38abcc76b0314fc85f91
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0
|
Security for code2image 0.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.