This package takes pictures of source code
Example code:
from sshot import shot
from PIL import Image
code='''
print('Hello World!')
'''
image=shot(code,lang='python')
Image.fromarray(image).save('code.png')
The code above will create something like:
Use in command line:
sshot -i test.py -l python -o code.png
sshot -i test.py -l python -o code.png -b bg.png # Add background image.
sshot -i test.py -l python -o code.png -b 00FF00FF0000 # Red code background color, green line number background color.
sshot -i test.py -l python # Show the image in a tkinter window.
It is also supported to set the background image of code, like:
from sshot import shot
from PIL import Image
from sshot.background import Background
import numpy as np
code='''
print('Hello World!')
'''
bg=np.array(Image.open('bg.png'))
image=shot(code,lang='python',background=Background(bg))
Image.fromarray(image).save('code.png')
Bugs below are fixed in this version:
- Error when reading GIF files. (IndexError: too many indices for array: array is 2-dimensional, but 3 were indexed.)
- SVG files are read incorrectly.
- Error when reading JSON files. This version's command line tool is better at guessing the language of the code.
Syntax highlight config in JSON file.
A correct syntax highlight config should have a 'config' key. It can also have an optional 'default' key.
The 'config' key is a dictionary, the key in that dictionary stands for the token name in the TokenChecker class (builtin, identifier, etc.) The 'default' key stands for the default color.
For example:
{
"config": {
"builtin": [127,0,0],
"exception": [0,127,0],
"string": [0,0,127]
},
"default": [127,127,127]
}
Using the JSON file above to create a picture of the code "print('Hello World!'), you will get:
Release files for sourceshot 2.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sourceshot-2.0.1.tar.gz | 7.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sourceshot-2.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.9 kB
Release files / sourceshot-2.0.1.tar.gz
| Download URL | sourceshot-2.0.1.tar.gz |
|---|---|
| Size | 7.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
24bdaa2d5fe0efcdf2914e75534262e2808cda94a1a6b672fb1c15241bbaef13
|
|
BLAKE2b-256 checksum How to use checksums |
7d80de3ffc722e695e0cb215263be22e87744563119dbefd15ae6c116ea1e81f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.7.0
|
Release files / sourceshot-2.0.1-py3-none-any.whl
| Download URL | sourceshot-2.0.1-py3-none-any.whl |
|---|---|
| Size | 9.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6a315ce1bd1bf00be9911079532dfedac307e8f70b730b15e0a05244c41d5b85
|
|
BLAKE2b-256 checksum How to use checksums |
e998606d82eda68f0e9c106e0d002487058a43ce75d1df6d068eab0028953fa7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.7.0
|