This little command line script provides a tool that creates a pixel art for bricks like LEGO®. It creates LDraw™ files or output streams for other tools like LeoCAD.
The following libraries must be installed:
The simplest use works on only two commands. This required commands are src_image
and input_palette
. However, it is recommended that you set the size
command for large input images, otherwise the calculation can take time.
The examples below in section
PixelArt examples
give an idea of the expected execution times.
Feel free to use the help with --help
.
$ ./ldraw_pixelart.py --src_image images.jpg --input_palette colors.csv > pixelart.ldr
$ ./ldraw_pixelart.py --src_image images.jpg --input_palette ldraw_colors.csv --size 32 32 > pixelart.ldr
$ ./ldraw_pixelart.py --src_image images.jpg --input_palette ldraw_colors.csv --size 32 32 --ldr_path pixelart.ldr
First the image is loaded. The image is then scaled to the specified size. The scaled image is quantized using the configured input color palette. Quantization is a pixel-by-pixel replacement for colors with an euclidean distance. This quantized image can also quantize with a second color palette. This quantized image can also be quantized using a second color palette. Why? Sometimes the shortest distance colors are not the best solution. The first color palette defines the source color in a first direction and the second palette defines the final color.
The last picture is passed to the Pixel Art module. This generator creates a rectangle or a rounded 1x1 plate brick for each pixel. Finally, the tool creates the output stream or file.
The source code is poorly tested (three day hack) and could crash. I take no responsibility and give no guarantee for the use of the program.
- Multithreaded quantization doesn't work
- No multithreaded string generation
- No anti aliasing filter
- Maybe a clipping problem?
All pixel arts was rendered with Intel® Core™ i7-7500U and the color palette ldraw_colors.csv
.
Name: Kylo Ren, size: 160x90p, elapsed time: 3s