pic2stl
is a Python package that converts images to 3D STL models. It reads an image, translates it into a 3D mesh, and exports the mesh in STL format. This package is ideal for creating 3D printable models from logos, silhouettes, and other high-contrast images.
- Convert images to 3D STL meshes
- Set extrusion height for 3D models
- Optionally add a base plane for enhanced model adhesion
- Compatible with any mainstream image format
To use this package, ensure that you have the required dependencies installed:
pip install numpy Pillow numpy-stl scipy
def image_to_stl(image_path, output_path, extrusion_height, add_base=False, base_thickness=0)
-
image_path
: Path to the input image. -
output_path
: Path to save the generated STL file. -
extrusion_height
: Height of the 3D model extrusion. -
add_base
(Optional, defaultFalse
): Adds a base plane if set toTrue
. -
base_thickness
(Optional, default1
): Thickness of the base plane.
# Convert an image to STL
image_to_stl('path/to/input_image.png', 'output.stl', extrusion_height=3, add_base=True, base_thickness=2)
- Load Image: The function reads the input image and converts it to grayscale if needed.
- Binary Conversion: Pixels above a specific threshold are considered "on," and those below are "off."
- Mesh Creation: A 3D mesh is generated based on the "on" pixels, extruding vertically.
- Optional Base: Adds an optional base to the bottom of the model for stability.
- Export to STL: The mesh is then exported to STL format.
This package is distributed under the MIT License.
Contributions are welcome. Please submit issues or pull requests to help improve this package!