img2stl is a Python package that converts images to 3D STL models.
Project description
pic2stl Image Converter
Overview
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.
Features
- 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
Installation
To use this package, ensure that you have the required dependencies installed:
pip install numpy Pillow numpy-stl scipy
Usage
Function
def image_to_stl(image_path, output_path, extrusion_height, add_base=False, base_thickness=0)
Parameters
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.
Example
# Convert an image to STL
image_to_stl('path/to/input_image.png', 'output.stl', extrusion_height=3, add_base=True, base_thickness=2)
How It Works
- 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.
License
This package is distributed under the MIT License.
Contribution
Contributions are welcome. Please submit issues or pull requests to help improve this package!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pic2stl-10.0.8.tar.gz
.
File metadata
- Download URL: pic2stl-10.0.8.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 139d65ae6172b1b9623ad0078cfc6db2f02c8dd847412d1b4f403c1db051092d |
|
MD5 | 68164ef47151fe00da8f6372a936f1e2 |
|
BLAKE2b-256 | 6c1d927b08e15ea15af2ee873f7dd73740df2e1be261cbe930ea1eb73eca2849 |
File details
Details for the file pic2stl-10.0.8-py3-none-any.whl
.
File metadata
- Download URL: pic2stl-10.0.8-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31c799096038260fd072e8662b85a6ea250520b4385bc608ded3f5f18b590b0d |
|
MD5 | ed65fb56ba8dd2f47ae4fe7241f8fbe7 |
|
BLAKE2b-256 | 274d987c47ca9bec01768e47e856d6e0e3c21d48d51fd8e588e4312371dcfa38 |