From Gentoo Wiki
Jump to: navigation, search

Designed by Vincent Sanders and released under MIT licence, PNG23D is a command line tool allowing to make a 3d file from a PNG image.

Different picture densities define different heights in 3d file generated. All the hard work is to customize source pictures, accorded to PNG23D settings, to get good printing files.

Many parameters can be set, among others: 3d object sizes, height levels number, output format –for example an .stl file to be printed, or a .scad one to be edited in OpenScad (media-gfx/openscad), etc.


PNG23D is not in Portage tree or Gentoo overlays, so installation is done by compiling sources found on GitHub.

Before compiling, as PNG23D relies on the libpng library for its PNG image handling (Vincent says), be sure that media-libs/libpng is installed:

user $emerge --info libpng

If not:

root #emerge --ask media-libs/libpng

Then clone Git repository, for example in /usr/src:

root #cd /usr/src

Compiling and installing:

root #cd /usr/src/PNG23D
root #make && make install

An Error?

If ‘STDIN_FILENO’ undeclared error is generated after make…:

CODE ‘STDIN_FILENO’ undeclared error
bitmap.c:46:25: error: ‘STDIN_FILENO’ undeclared (first use in this function)
         fp = fdopen(dup(STDIN_FILENO), "rb");

… add #include <unistd.h> at the beggining of /etc/src/PNG23D/bitmap.c:

FILE /etc/src/PNG23D/bitmap.cEditing bitmap.c
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h> /* added line */
#include <png.h>
#include "bitmap.h"

Then compile again.

Without Git

Alternatively without git, sources can be downloaded, unziped an compiled in another location.

Man Page

For the man page to be installed, be sure that /usr/local/share/man/man1 directory exists, create it if needed:

root #mkdir -p /usr/local/share/man/man1

Then install the man page (which will later be accessed by man png23d):

root #make install-man


Simple usage making an .stl file:

user $png23d -o stl /path/to/input/file.png /path/to/output/file.stl

And making an .scad file:

user $png23d -o scad /path/to/input/file.png /path/to/output/file.scad

External resources