Your goal is to implement a Python program that arranges a set of images of random sizes and shapes into a PDF in a way that minimizes the total space used, while preserving each image's original aspect ratio.
This task tests your understanding of:
- Rectangle packing algorithms
- Image processing
- PDF generation
- Efficient code design
-
Clone the repository to your local machine.
-
Create a virtual environment for the project.
-
Install dependencies from
requirements.txt. -
Generate sample images using
sample_data_generation.py. -
Read images from a folder (
input_images/).
Images may contain transparent backgrounds and random shapes. -
Preprocess images:
- Remove transparent background (optional for packing optimization)
- Crop images to the bounding box of the visible area
- Preserve original aspect ratio
-
Pack images optimally into pages of a PDF:
- Each page can have a fixed size (A4, Letter, or configurable)
- Minimize wasted space
-
Generate a PDF (
output.pdf) with all images properly packed. -
Update the requirements.txt file with the necessary dependencies.
-
Update README.md with instructions for running the program.
| File | Description | Additional Notes |
|---|---|---|
sample_data_generation.py |
Script for generating sample images | Run python sample_data_generation.py to generate sample images |
input_images/ |
Folder containing generated images | Folder will be created if it doesn't exist when the script is run |
task_1_starter_code.py |
Starter template for implementing the packing algorithm | |
README.md |
This file | |
requirements.txt |
List of dependencies required to run the program | Install these in a virtual environment |
Follow these steps to get started:
- Create a virtual environment for the project.
- Install dependencies from
requirements.txt. - Run the
sample_data_generation.pyscript to generate sample images. - Edit and implement the task in
task_1_starter_code.py. - Run your solution to generate the output PDF.
- Optimize image compression to reduce file size.
- Implement a command-line interface for running the program.
- Add documentation to explain the program's functionality.
- Implement error handling for handling edge cases.