Convert source code into beautiful syntax-highlighted and auto-cropped images
Project description
PySnapCode
PySnapCode is a lightweight Python library designed to transform your source code into beautiful, syntax-highlighted, and auto-cropped images. It is the perfect tool for sharing code snippets on social media, technical blogs, or project documentation.
Prerequisites (Mandatory)
To ensure this library functions correctly, you must install the following two external dependencies.
Installation Guide
If you need help setting up these dependencies, follow this step-by-step video tutorial: View Tutorial on YouTube
1. Poppler (Required for Image Generation)
- Windows: Download the latest version from the Poppler for Windows Releases.
- Setup: Extract the ZIP file and copy the path to the
binfolder. You will need to provide this path in your Python script.
2. wkhtmltopdf (Required for PDF Rendering)
- Download: Get the installer from the official wkhtmltopdf website.
- Setup: Run the installer. It is highly recommended to add it to your system PATH during the installation process.
Installation
You can install PySnapCode directly from PyPI using pip:
pip install PySnapCode
### Usage
Basic Example
This example shows how to convert a Python file using the default dark theme.
```python
from py_snap_code import CodeConverter
# Initialize the converter with your Poppler bin path
conv = CodeConverter(poppler_path=r'C:\path\to\your\poppler\bin')
# Convert your python file to a cropped image
conv.convert('main.py', output_name='my_code_snap')
Advanced Customization
You can fully customize the colors and font size to match your personal style or brand.
from py_snap_code import CodeConverter
# Define a custom theme (e.g., Dracula-inspired)
my_theme = {
'bg': '#282a36', # Background color
'text': '#f8f8f2', # Primary text color
'keywords': '#ff79c6', # Python keywords
'numbers': '#bd93f9', # Numbers
'line_num': '#6272a4' # Line numbers color
}
conv = CodeConverter(
poppler_path=r'C:\poppler\bin',
custom_colors=my_theme,
font_size="18px"
)
conv.convert('script.py', output_name='pro_snippet')
Key Features
Auto-Crop: Automatically detects the code area and trims excess white space.
Syntax Highlighting: Built-in support for standard Python keywords and operators.
Theming Engine: Full control over background, text, and highlighting color palettes.
Professional Padding: Adds clean, consistent padding around your code for a better visual look.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support & Donations
If you find this library helpful and want to support its development, you can buy me a coffee here:
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pysnapcode-0.1.1.tar.gz.
File metadata
- Download URL: pysnapcode-0.1.1.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6772a965a7c1ad884cbd6c3d5d1635a5f036327aab6f8a490d2e4f056b2678f0
|
|
| MD5 |
2b6ea02f75ea0f0f7e949241e8ae4b1a
|
|
| BLAKE2b-256 |
76ccb44a543a09159046b30bdfa0893e21acfb2350738bf50e344298a84352b4
|
File details
Details for the file pysnapcode-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pysnapcode-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
abc2bec79610a47891de5696cfa5f96f9220a74b8a8e9f6c1e8dcd6857aa5e17
|
|
| MD5 |
4a54379beb476344f764db00cb104e24
|
|
| BLAKE2b-256 |
cde631dc03bbb1ca451b12fd04dd3992ef7cca6a23c87fd8f65d952c6d2a56f8
|