This tool generates halftone from a given image (amazing video about halftone).
The output is in a from of an svg file.
The tool was created to generate halftone images that can be printed with a pen plotter. This guided the choice of the parameters and the output format.
![]() |
![]() |
|---|
I used Python 3.12.
For installation, I recommend using miniconda (quick command line installation guide).
After installing miniconda, create a new environment by running:
conda create --name halftone python=3.12Activate the environment by running:
conda activate halftoneAfter cloning or downloading the repository, install the required packages by running:
pip install -r requirements.txtFunction generate_halftone from src/halftone.py splits the given image is split into four layers (C, M, Y, K).
Each layer consists of points on a grid.
The size of the points is proportional to the average color intensity of the area covered by the circle.
Grids are rotated to a given angle to mitigate the Moiré pattern.
The function has the following parameters:
| Parameter | Description | Default |
|---|---|---|
image_path |
path to the image | |
save_path |
path to save the svg | |
paper_w |
width of the paper in meters | |
paper_h |
height of the paper in meters | |
max_dot_size |
maximum size of the dots in meters | |
colors |
list of hex color codes for each layer | ["#00ffff", "#ff00ff", "#ffff00", "#000000"] |
angles |
list of angles in degrees for each layer | [15, 75, 0, 45] |
alphas |
list of opacities for each layer | [1, 1, 1, 1] |
lws |
list of line widths in millimeters for each layer | [1, 1, 1, 1] |
pad |
padding in meters | 0 |
use_black |
whether to plot the black layer or not | False |
fit_how |
how to fit the image to the paper (options: "fit", "fit-width", "fit-height") |
"fit" |
dot_fill_how |
how to fill the dot. This is done because the plotter software does not support filled circles. (options: "circles", "lines") |
"circles" |
After installing and activating the environment, you can run python in the command line:
pythonThen you can import the function and run it with your parameters:
import src.halftone as ht
ht.generate_halftone("example/tatry.jpeg","./example", 0.141, 0.1, 0.003, lws=[0.4,0.4,0.4,0.4], alphas=[0.8, 0.8, 0.8, 0.8], pad=0.005)Please see the example for a detailed guide on how to use the tool in a jupyter notebook.
You can contribute to this project by creating a pull request or submitting an issue.
This project is licensed under the MIT License (see the LICENSE file for details).

