Skip to main content

Convert CSV files to PNG/JPEG images with Unicode support

Project description

csv2img

Python Version License: MIT Tests

Convert CSV files to high-quality PNG/JPEG images with full Unicode support (CJK, Arabic, Hebrew, Devanagari, etc.).

Features

  • Simple API: Convert CSV to PNG/JPEG with one line of code
  • High Quality: Configurable DPI (default 300) for crisp output
  • Full Unicode: Auto-detects scripts and uses appropriate fonts — CJK, Arabic, Hebrew, Devanagari, Latin Extended
  • Multi-page Support: Automatically handles CSV files that span multiple pages
  • Flexible Formats: Output as PNG or JPEG
  • Custom Delimiters: Supports TSV, semicolon-separated, or any delimiter
  • CLI Support: Use from command line or as a Python library
  • Zero csv2pdf dependency: Pure fpdf2 + PyMuPDF

Installation

From PyPI (recommended)

pip install csv2img

From Source

git clone https://github.com/Shun-Calvin/csv2img.git
cd csv2img
pip install -e .

Usage

Python Library

Basic Usage

from csv2img import saveas

# Convert a CSV file to PNG images
output_files = saveas("data.csv")
print(f"Generated {len(output_files)} images: {output_files}")

Unicode (CJK) — Auto-Detected

from csv2img import saveas

# Chinese/Japanese/Korean text is auto-detected and rendered with Noto Sans CJK
output_files = saveas("chinese_data.csv")
# Output: chinese_data1.png (with proper CJK characters)

Custom Format & DPI

from csv2img import saveas

# Convert to JPEG at 600 DPI
output_files = saveas("report.csv", dpi=600, output_format="jpeg")

Custom Delimiter (TSV, semicolon, etc.)

from csv2img import saveas

# Tab-separated values
output_files = saveas("data.tsv", delimiter="\t")

# Semicolon-separated (common in European locales)
output_files = saveas("data.csv", delimiter=";")

Custom Font

from csv2img import saveas

# Use your own TTF/OTF font file
output_files = saveas("data.csv", font_path="/path/to/your/font.ttf")

Using the Alternative Function Name

from csv2img import convert_file

output_files = convert_file("data.csv", output_dir="./images", dpi=300)

Command Line Interface

After installation, you can use the csv2img command:

# Basic usage
csv2img data.csv

# Specify output directory
csv2img data.csv ./output

# Specify output directory and DPI
csv2img data.csv ./output 600

# Specify output format
csv2img data.csv ./output 300 --format jpeg

# Specify delimiter (TSV)
csv2img data.csv ./output 300 --delimiter $'\t'

# Custom font
csv2img data.csv ./output 300 --font /path/to/font.ttf

API Reference

saveas(source, dpi=300, output_dir=None, output_format="png", delimiter=",", font_path=None)

Convert a CSV file to image files.

Parameters:

  • source (str | Path): Path to the source CSV file (required)
  • dpi (int): Resolution for output images (default: 300)
  • output_dir (str, optional): Directory to save output images (default: same as source)
  • output_format (str): Output format — 'png' or 'jpeg' (default: 'png')
  • delimiter (str): CSV delimiter character (default: ',')
  • font_path (str, optional): Path to a TTF/OTF font file. If None, auto-detects from system fonts based on CSV content.

Returns:

  • List[str]: List of paths to the generated image files

Raises:

  • FileNotFoundError: If the source CSV file doesn't exist
  • ValueError: If the source file is not a CSV file or format is unsupported
  • ImportError: If required dependencies are not installed

SUPPORTED_FORMATS

A list of supported output formats: ["png", "jpeg", "jpg"]

Unicode Font Support

csv2img auto-detects the dominant script in your CSV and uses the appropriate font:

Script Unicode Range Font Used
CJK (Chinese/Japanese/Korean) \u4e00-\u9fff, \u3040-\u30ff Noto Sans CJK
Arabic \u0600-\u06ff Noto Sans Arabic
Hebrew \u0590-\u05ff Noto Sans Hebrew
Devanagari (Hindi, etc.) \u0900-\u097f Noto Sans Devanagari
Latin Extended \u0080-\u024f Noto Sans Mono

You can override auto-detection by passing font_path explicitly.

How It Works

  1. The CSV file is parsed using Python's built-in csv module (supports any delimiter)
  2. fpdf2 renders the table to a PDF with Unicode-aware TTF fonts
  3. PyMuPDF (fitz) renders each PDF page as a high-quality image
  4. The temporary PDF file is automatically cleaned up

Example:

  • Input: data.csv
  • Output: data1.png, data2.png, data3.png (if the CSV spans 3 pages)

Requirements

  • Python 3.7+
  • fpdf2 (PDF rendering with Unicode font support)
  • PyMuPDF (PDF to image rendering)

Troubleshooting

Font Missing for Specific Script

If your CSV contains characters not covered by the auto-detected font, pass a custom font:

from csv2img import saveas

# Use a font that covers your specific characters
output_files = saveas("data.csv", font_path="/path/to/font.ttf")

Permission Errors

Ensure you have write permissions in the output directory. If specifying a custom output directory, it will be created automatically if it doesn't exist.

Memory Issues

For very large CSV files:

  • Reduce the DPI setting (e.g., use 150 instead of 300)
  • Ensure sufficient disk space for temporary PDF and output images

Testing

pip install pytest
python -m pytest tests/ -v

Changelog

Version 0.4.0 (2026-06-17)

  • Removed csv2pdf dependency — pure fpdf2 + PyMuPDF implementation
  • Full Unicode support — auto-detects CJK, Arabic, Hebrew, Devanagari, Latin Extended
  • JPEG output format — PNG and JPEG both supported
  • Custom delimiter — TSV, semicolon, or any separator
  • Custom font path — pass your own TTF/OTF font file
  • Path object supportsource accepts str or Path
  • Empty CSV handling — returns [] instead of crashing
  • Output validation — verifies generated files exist and are non-empty
  • 🐛 Fixed PDF cleanup — removes temp PDF after return, not in finally
  • 📦 Updated dependenciescsv2pdf>=1.0.0fpdf2>=2.5.0

Version 0.3.0 (2026-04-07)

  • Added JPEG and PNG format support
  • Added delimiter parameter
  • Improved error handling and output validation

Version 0.2.0 (2026-04-07)

  • ✨ Added comprehensive error handling and input validation
  • ✨ Added type hints and docstrings
  • ✨ Added logging support
  • ✨ Added command-line interface
  • ✨ Added setup.py for proper package installation
  • ✨ Added requirements.txt
  • ✨ Improved documentation with examples
  • 🐛 Fixed temporary PDF cleanup
  • 📦 Added proper package structure

Version 0.1.0 (2022)

  • Initial release
  • Basic CSV to PNG conversion functionality

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

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

csv2img-1.0.1.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

csv2img-1.0.1-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file csv2img-1.0.1.tar.gz.

File metadata

  • Download URL: csv2img-1.0.1.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for csv2img-1.0.1.tar.gz
Algorithm Hash digest
SHA256 d9e6aa524657f23b5e142dafc72cf51b3508c5775c2d6906eefa677c045f2047
MD5 4d362074f50643eacdfe8567806fd89a
BLAKE2b-256 b542df9bd19712fc82b18fb6eb1631704fda69ea3d67fa00ea3b1377f36accdc

See more details on using hashes here.

Provenance

The following attestation bundles were made for csv2img-1.0.1.tar.gz:

Publisher: release.yml on Shun-Calvin/csv2img

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file csv2img-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: csv2img-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for csv2img-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 402e2893d2cdd0023b24d02949a7ea18b25b65883c602089b061660841ba0139
MD5 68a542b04424abc9d9867bf0d697c5fe
BLAKE2b-256 ef1511033cb9f8e6262d67d63857186272e41bc5b39903b005b3f40c77d41ad4

See more details on using hashes here.

Provenance

The following attestation bundles were made for csv2img-1.0.1-py3-none-any.whl:

Publisher: release.yml on Shun-Calvin/csv2img

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page