https://github.com/none-none1/sourceshot
Takes pictures of code!
https://github.com/none-none1/sourceshot
image-processing syntax-highlighting
Last synced: 10 months ago
JSON representation
Takes pictures of code!
- Host: GitHub
- URL: https://github.com/none-none1/sourceshot
- Owner: none-None1
- Created: 2023-06-29T01:35:02.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-02-19T13:40:18.000Z (over 2 years ago)
- Last Synced: 2025-08-26T01:46:33.380Z (10 months ago)
- Topics: image-processing, syntax-highlighting
- Language: Python
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://pepy.tech/project/sourceshot) [](https://pepy.tech/project/sourceshot) [](https://pepy.tech/project/sourceshot)
The purpose of this package is taking pictures of code.
To run sourceshot, do
```
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:
```commandline
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.
```
Here is a picture of a C++ program generated using this tool:

It is also supported to set the background image of code, like:
```python
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')
```
### 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:
```json
{
"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:

How to install?
```commandline
pip install sourceshot
```
[link](https://pypi.org/project/sourceshot/)