Convert images in a folder to PDF slides with automatic resolution analysis
Project description
Images to PDF Converter
A modern Python package that converts images in a folder into a professional PDF presentation, with each image displayed as a slide. Features automatic image analysis, resolution detection, and intelligent page sizing.
โจ Features
- ๐ผ๏ธ Multi-format Support: PNG, JPG, JPEG, GIF, and BMP
- ๐ Automatic Analysis: Analyzes resolution, DPI, format, and aspect ratio
- ๐ Smart Sizing: Automatically adjusts PDF page size based on image dimensions
- ๐ฏ Aspect Ratio Preservation: Maintains image proportions and centers content
- โก Fast Processing: Built with Pillow and ReportLab for optimal performance
- ๐ฅ๏ธ CLI & API: Use as command-line tool or Python library
- ๐ฆ Modern Packaging: Built with UV and follows Python packaging best practices
๐ Table of Contents
๐ Installation
From PyPI (once published)
pip install images2pdf-slides
From Source
Using UV (Recommended)
# Clone the repository
git clone https://github.com/Maheshkumar-novice/images2pdf-slides.git
cd images2pdf-slides
# Install with UV
uv pip install -e .
Using pip
# Clone the repository
git clone https://github.com/Maheshkumar-novice/images2pdf-slides.git
cd images2pdf-slides
# Install in editable mode
pip install -e .
๐ Quick Start
-
Prepare your images: Place images in a folder (e.g.,
images/) -
Run the converter:
images-to-pdf images/ -
Get your PDF: Find
output_slides.pdfin the current directory
That's it! ๐
๐ Usage
Command Line Interface
The package installs the images-to-pdf command:
# Use default 'images' folder and output filename
images-to-pdf
# Specify a custom input folder
images-to-pdf photos/
# Specify custom input folder and output filename
images-to-pdf photos/ -o presentation.pdf
# Show help message
images-to-pdf --help
# Show version
images-to-pdf --version
CLI Options
| Option | Short | Description | Default |
|---|---|---|---|
images_folder |
- | Folder containing images | images |
--output |
-o |
Output PDF filename | output_slides.pdf |
--version |
-v |
Show version number | - |
--help |
-h |
Show help message | - |
Python API
Use the package in your Python scripts:
from images_to_pdf import create_pdf_from_images, analyze_image
# Create PDF from all images in a folder
create_pdf_from_images("photos/", "output.pdf")
# Analyze a single image
info = analyze_image("photo.jpg")
print(f"Resolution: {info['width']}x{info['height']} pixels")
print(f"Format: {info['format']}")
print(f"DPI: {info['dpi']}")
print(f"Aspect Ratio: {info['aspect_ratio']:.2f}")
API Reference
create_pdf_from_images(images_folder, output_pdf)
Convert all images in a folder to a PDF presentation.
Parameters:
images_folder(str): Path to folder containing imagesoutput_pdf(str): Output PDF filename
Returns: None
Supported formats: PNG, JPG, JPEG, GIF, BMP
analyze_image(image_path)
Analyze properties of a single image.
Parameters:
image_path(str | Path): Path to image file
Returns: Dictionary with keys:
path: Path to the imagewidth: Image width in pixelsheight: Image height in pixelsmode: Color mode (e.g., 'RGB', 'RGBA')format: Image format (e.g., 'PNG', 'JPEG')dpi: DPI tuple (x, y)aspect_ratio: Width/height ratio
๐ฆ Requirements
- Python: 3.8 or higher
- Dependencies:
- Pillow >= 10.0.0 (Image processing)
- ReportLab >= 4.0.0 (PDF generation)
All dependencies are automatically installed when you install the package.
๐ก Examples
Example 1: Basic Usage
# Place images in 'images' folder
mkdir images
cp ~/Pictures/*.jpg images/
# Convert to PDF
images-to-pdf
# Output: output_slides.pdf created with all images as slides
Example 2: Custom Output
# Create presentation with custom name
images-to-pdf vacation-photos/ -o vacation-2025.pdf
Example 3: Python Script
from pathlib import Path
from images_to_pdf import create_pdf_from_images, analyze_image
# Analyze all images first
image_folder = Path("screenshots")
for img_file in image_folder.glob("*.png"):
info = analyze_image(img_file)
print(f"{img_file.name}: {info['width']}x{info['height']}")
# Create PDF
create_pdf_from_images("screenshots", "documentation.pdf")
Example Output
When you run the converter, you'll see detailed analysis:
Found 5 images
================================================================================
Image: Screenshot 2025-11-20 at 4.37.39 PM.png
Resolution: 2880 x 1800 pixels
Format: PNG
Color Mode: RGBA
DPI: (144.0, 144.0)
Aspect Ratio: 1.60
Image: Screenshot 2025-11-20 at 4.37.47 PM.png
Resolution: 2880 x 1800 pixels
Format: PNG
Color Mode: RGBA
DPI: (144.0, 144.0)
Aspect Ratio: 1.60
[... more images ...]
================================================================================
Creating PDF: output_slides.pdf
Adding slide 1/5: Screenshot 2025-11-20 at 4.37.39 PM.png
Adding slide 2/5: Screenshot 2025-11-20 at 4.37.47 PM.png
Adding slide 3/5: Screenshot 2025-11-20 at 4.38.08 PM.png
Adding slide 4/5: Screenshot 2025-11-20 at 4.38.16 PM.png
Adding slide 5/5: Screenshot 2025-11-20 at 4.38.44 PM.png
โ PDF created successfully: output_slides.pdf
Total pages: 5
๐ ๏ธ Development
Setting Up Development Environment
# Clone the repository
git clone https://github.com/Maheshkumar-novice/images2pdf-slides.git
cd images2pdf-slides
# Install with development dependencies using UV
uv sync --all-extras
# Or using pip
pip install -e ".[dev]"
Project Structure
images2pdf-slides/
โโโ src/
โ โโโ images_to_pdf/
โ โโโ __init__.py # Package initialization and exports
โ โโโ core.py # Core conversion logic
โ โโโ cli.py # Command-line interface
โ โโโ py.typed # Type hints marker
โโโ dist/ # Built distributions (gitignored)
โโโ pyproject.toml # Package configuration
โโโ LICENSE # MIT License
โโโ README.md # This file
โโโ .gitignore # Git ignore rules
Development Workflow
# Format code with black
uv run black src/
# Lint code with ruff
uv run ruff check src/
# Run type checking with mypy
uv run mypy src/
# Run tests (if you add them)
uv run pytest
# Test the CLI locally
uv run images-to-pdf images/
Adding Features
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Make your changes in
src/images_to_pdf/ - Test your changes locally
- Submit a pull request
๐ค Publishing
Building the Package
# Build distribution files
uv build
# Output: dist/images_to_pdf-0.1.0-py3-none-any.whl
# dist/images_to_pdf-0.1.0.tar.gz
Publishing to PyPI
Prerequisites
-
Create accounts:
- Test PyPI: https://test.pypi.org/account/register/
- Production PyPI: https://pypi.org/account/register/
-
Enable 2FA (required)
-
Create API token:
- Go to Account Settings โ API tokens
- Create token for this project
Publish Steps
# 1. Test on Test PyPI first (recommended)
uv publish --publish-url https://test.pypi.org/legacy/
# 2. Verify installation from Test PyPI
pip install --index-url https://test.pypi.org/simple/ images2pdf-slides
# 3. If everything works, publish to production PyPI
uv publish
# 4. Install from PyPI
pip install images2pdf-slides
Publishing with Token
# Set environment variable (recommended)
export UV_PUBLISH_TOKEN="pypi-..."
uv publish
# Or pass directly
uv publish --token pypi-...
Version Management
Update version in pyproject.toml:
[project]
name = "images-to-pdf"
version = "0.2.0" # Increment version
Follow Semantic Versioning:
- MAJOR: Breaking changes (e.g., 1.0.0 โ 2.0.0)
- MINOR: New features, backward compatible (e.g., 1.0.0 โ 1.1.0)
- PATCH: Bug fixes (e.g., 1.0.0 โ 1.0.1)
๐ค Contributing
Contributions are welcome! Here's how you can help:
- Report bugs: Open an issue describing the problem
- Suggest features: Open an issue with your idea
- Submit PRs: Fork, create a branch, make changes, submit PR
- Improve docs: Help make documentation better
Please ensure your code:
- Follows PEP 8 style guidelines
- Includes docstrings for functions
- Works with Python 3.8+
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
MIT License
Copyright (c) 2025 Maheshkumar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction...
๐ Links
- Homepage: https://github.com/Maheshkumar-novice/images2pdf-slides
- PyPI: https://pypi.org/project/images2pdf-slides/ (once published)
- Issues: https://github.com/Maheshkumar-novice/images2pdf-slides/issues
- Documentation: This README
โ FAQ
Q: What image formats are supported?
A: PNG, JPG, JPEG, GIF, and BMP formats are supported.
Q: How are images ordered in the PDF?
A: Images are sorted alphabetically by filename. To control the order, name your files with prefixes like 01-image.png, 02-image.png, etc.
Q: Can I customize page sizes?
A: Currently, page sizes are automatically calculated based on the first image's aspect ratio. For custom page sizes, you can modify the core.py file or use the Python API to build your own logic.
Q: What if my folder has no images?
A: The program will display "No images found in {folder}" and exit gracefully.
Q: Does this work with very large images?
A: Yes, but be aware that very large images will increase PDF file size. The images are not compressed beyond their original format.
Q: Can I use this in my commercial project?
A: Yes! The MIT license allows commercial use. Just include the license notice.
๐ Acknowledgments
Built with:
Made with โค๏ธ by Maheshkumar
Star โญ this repo if you find it helpful!
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 images2pdf_slides-0.1.0.tar.gz.
File metadata
- Download URL: images2pdf_slides-0.1.0.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c185f10df2457ff1c1fa3b8e88232d04d4319dc378989f72e5252077c954fe8
|
|
| MD5 |
f8b85917c59e1bb277f2affdfb263f4f
|
|
| BLAKE2b-256 |
ad9b212f102d64da3fa1614e38c78d0c33a0b7f51fcd8d068bfa905d71f6adcb
|
File details
Details for the file images2pdf_slides-0.1.0-py3-none-any.whl.
File metadata
- Download URL: images2pdf_slides-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3ad21c4e7a1ee3a6f3d41612e997069eb0a209d2e5018bed6259f9553e9520db
|
|
| MD5 |
3d214de340384466aee0fdfdfb262db5
|
|
| BLAKE2b-256 |
8fddc5345d3cd9ea9e5dafcef64b3e493b154535ce549b1cc24282f4c8651568
|