Takes pictures of code!
Project description
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:
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file sourceshot-2.0.0.tar.gz
.
File metadata
- Download URL: sourceshot-2.0.0.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0cb3351b62fd2b4f1a6b740faa7f60e997ca6e583890359c29df8263d1ecd883 |
|
MD5 | a72d559646e04bdbec807b3ce0abe1fd |
|
BLAKE2b-256 | 96b995ec80edda2f93a290fb5b5b85ace5e9c0189d2f3f79effab0949b8b09c3 |
File details
Details for the file sourceshot-2.0.0-py3-none-any.whl
.
File metadata
- Download URL: sourceshot-2.0.0-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 726b875d9c8582aa25092517d750a22b16e56b4492b3b0603d7298dbd0df5066 |
|
MD5 | 9721430437126f591f993db821448a93 |
|
BLAKE2b-256 | 5ae43775b9e899907baa55a37ade0e1b9629456c9685e6cbe48926837ae7e058 |