Files
image2exel/readme.md
2026-03-29 20:56:10 +03:30

57 lines
2.1 KiB
Markdown

# Image to Excel Converter
A simple Python command-line application that converts an image file into an Excel (`.xlsx`) spreadsheet. It accomplishes this by taking blocks of pixels from the original image, calculating their average color, and setting the background color of the corresponding Excel cells to match, creating a pixel-art representation of the image.
## Prerequisites
To run this script, you will need Python 3 installed on your system along with a couple of external libraries.
### Environment Setup
1. **Clone or download** this repository (or just the `convert.py` script) to your local machine.
2. **(Optional but recommended)** Create a virtual environment:
```bash
python -m venv venv
source venv/bin/activate # On Windows use: venv\Scripts\activate
```
3. **Install dependencies**:
The script relies on `Pillow` for image processing and `openpyxl` for Excel generation. Install them using pip:
```bash
pip install Pillow openpyxl
```
## Usage
You can use the script directly from the command line by passing the path to the image you want to convert as an argument.
### Command Line Interface
```bash
python convert.py path/to/your/image.jpg
```
**Example:**
```bash
python convert.py profile_pic.png
```
**Output:**
The script will process the image in 40x10 pixel blocks, calculate the average RGB values, and map them to Excel cells. It will then generate an Excel file in the same directory, using the original image's name (e.g., `profile_pic.xlsx`).
```text
initiating...
started...
Processing file: profile_pic.png
exel file "profile_pic.xlsx" saved.
```
### Using as a Module
You can also import the conversion function into your own Python scripts:
```python
from convert import convert_to_xl
output_file = convert_to_xl("path/to/image.png")
print(f"Successfully generated: {output_file}")
```
## How it works
The script divides the image into horizontal blocks of 40 pixels and vertical blocks of 10 pixels. It iterates through the 400 pixels in each block, calculates the average RGB color, converts that color to a Hex code, and applies it as a solid fill to the corresponding cell in the generated `.xlsx` file.