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. Perfect for sharing code snippets on social media, blogs, or documentation.
âڑ ï¸ڈ Prerequisites (Mandatory)
To use this library, you must install two external tools. Without them, the library will not function correctly.
ًںژ¥ Installation Guide
If you are unsure how to set up the dependencies, watch this step-by-step video tutorial: ًں‘‰ Watch the Tutorial on YouTube
1. Poppler (For Image Generation)
- Windows: Download the latest version from Poppler for Windows.
- Setup: Extract the ZIP file and provide the path to the
binfolder in the code (see Usage below).
2. wkhtmltopdf (For PDF Rendering)
- Download: Get the installer from the official wkhtmltopdf website.
- Setup: Run the installer and ensure it is added to your System PATH during installation.
ًںڑ€ Installation
Install the library using pip:
pip install PySnapCode
ًں› Usage
Basic Example
Python
from py_snap_code import CodeConverter
# Initialize the converter with your Poppler 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 (Custom Colors & Font Size)
Python
from py_snap_code import CodeConverter
# Define a custom theme
my_theme = {
'bg': '#282a36', # Background color
'text': '#f8f8f2', # Normal 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')
ًں“ Features
Auto-Crop: Automatically trims the white space around your code.
Syntax Highlighting: Supports all standard Python keywords and operators.
Custom Themes: Full control over background, text, and highlight colors.
Clean Output: Generates high-resolution images with professional padding.
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.0.tar.gz.
File metadata
- Download URL: pysnapcode-0.1.0.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
70c83f92da884d0cc61ded582ad1b41b4fb6c6efefb79036c746863a2485c9be
|
|
| MD5 |
3bf1f5312b6a3b44719ebe1e644df59d
|
|
| BLAKE2b-256 |
713f6be473402decdb6056a656743e67ec7bb33c532ba1b25818557b650030f6
|
File details
Details for the file pysnapcode-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pysnapcode-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.9 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 |
a683ee17989fbf3f2893357fd79cd19501105cf92ad94887c8070eea2cd946d3
|
|
| MD5 |
ab7bf25b6050572e6858b37cdb90dd8c
|
|
| BLAKE2b-256 |
6e1afe7e78d4b507200d075c53f3f41ca1aaea3d1239b7edb7ed4d556f50b16b
|