This Python script converts images (including SVG) to .npy files and vice versa.
- Convert JPEG, PNG, SVG (and more) to NumPy (
.npy) format. - Convert
.npyfiles back into images. - Supports SVG conversion using
cairosvg.
Clone the repository and install dependencies:
git clone https://github.com/HappySR/image-to-npy-bi-directional-converter.git
pip install -r requirements.txtnumpyPillowcairosvg(only needed for SVG support)
Install dependencies manually if needed:
pip install numpy pillow cairosvgIf you keep your script in the root directory, you can run it like this:
python image_to_npy_bidirectional.py --mode to_npy --input image.jpg --output image.npypython image_to_npy_bidirectional.py --mode to_image --input image.npy --output output.pngpython image_to_npy_bidirectional.py --mode to_npy --input image.svg --output image.npyYou can also provide absolute or relative paths for input and output files.
(Relative to the script's location)
python image_to_npy_bidirectional.py --mode to_npy --input images/sample.jpg --output npy_files/sample.npypython image_to_npy_bidirectional.py --mode to_image --input npy_files/sample.npy --output output_images/sample.png(Replace /path/to/ with the actual directory)
python image_to_npy_bidirectional.py --mode to_npy --input /home/user/images/sample.jpg --output /home/user/npy_files/sample.npypython image_to_npy_bidirectional.py --mode to_image --input /home/user/npy_files/sample.npy --output /home/user/output_images/sample.png- SVG images are first converted to PNG before saving as
.npy. - The script automatically detects formats and handles conversions accordingly.
Feel free to submit issues or pull requests!
This project is licensed under the MIT License.