This Rust program applies a dot matrix effect to an image, turning a certain percentage of the image's pixels into black dots arranged in a grid pattern. The dots are distributed evenly across the image. The percentage of black dots is configurable via the command-line argument.
- Reads an image file (JPEG, PNG, etc.).
- Applies a dot matrix transformation, where a specified percentage of the pixels are turned into black dots.
- Supports flexible dot matrix patterns with grid spacing based on the percentage of black dots.
Original Image:
With 25% pixels turned to black in a matrix
- Rust 1.60 or later
- The
image
crate, which is used to handle image processing.
To use the program, clone this repository:
git clone https://github.com/your-username/pixel-matrix-image.git
cd pixel-matrix-image
Ensure that you have Rust installed. You can check this by running:
rustc --version
If you haven't installed Rust, you can follow the instructions here Once you have Rust installed, build the project:
cargo build --release
This will compile the program and create an executable in the target/release/
directory.
The program accepts two command-line arguments:
<image_path>
: Path to the image file you want to process.<percentage>
: The percentage of the image's pixels that will be turned into black dots. It must be a number between 0 and 100.
cargo run image.png 25
This will process image.png
, turning 25% of the image's pixels into black dots arranged in a grid, and save the transformed image as output.png
in the current directory.
- The program reads the image file from the specified path and loads it into memory.
- It calculates the number of pixels to convert into black dots based on the provided percentage.
- It then applies the dot matrix effect by placing black dots in a grid pattern at regular intervals across the image.
- If the image fails to load (e.g., the file path is invalid or the image is not supported), an error message is displayed.
- If the program fails to save the modified image (due to issues like file permissions), an error message is also displayed.
This project is licensed under the MIT License.