OpenSCAD surface Gimp Export Plugin

by ffaat, published

OpenSCAD surface Gimp Export Plugin by ffaat Nov 22, 2012


Liked By

View All

Give a Shout Out

If you print this Thing and display it in public proudly give attribution by printing and displaying this tag.

Print Thing Tag

Thing Statistics

9289Views 1866Downloads Found in 3D Printing


I've written a gimp python plugin to export the openscad surface format. The pic shows the greyscale height-field and the resultant openscad surface.
This was done to design terrain in gimp and send the tiles to a 3d printer.


Extract the python file an put it in your gimp plugin directory.
Open a greyscale image in gimp then save it with a ".dat" extension (i.e. "testsurface.dat"

Then use this in openscad comme ca:

surface(file = "testsurface.dat", center=true, convexity = 5);

and scale as needed...

Note that really large surface files will cause openSCAD to die horribly, so it is best to prescale the image before exporting.

I've adjusted the scaling so the 0->255 will map to exactly -0.5 -> 0.5.
Note that the surface routine seems to add a 1 unit high base to the imported surface, so the actual surface rendered will be from -1.5 -> 0.5, so you need to intersect it with a 1 unit high centered box to trim off this base.

Also not that the surface import function does NOT create steps - it generates the triangles vertices based on the pixel values.

This means for a 4x4 image that is a B&W 2x2 checkboard you end up with:
0.5 0.5 -0.5 -0.5
0.5 0.5 -0.5 -0.5
-0.5 -0.5 0.5 0.5
-0.5 -0.5 0.5 0.5

which renders 3x3 units x by y. consisting of two tableaus at -0.5 and two tableaus at 0.5 with sloped surfaces between (which might not be what you were expecting). One of the example images shows this.

More from 3D Printing

view more

All Apps

Upgrade this Thing with Thingiverse Apps

Tools and Utilities

Repair, slice, or enhance this Thing

Auto-magically prepare your 3D models for 3D printing. A cloud based 3D models Preparing and Healing solution for 3D Printing, MakePrintable provides features for model repairing, wall thickness...

App Info Launch App

Thanks, but still confused on how to install this. I am new to Openscad. Any help would be very appreciated

Are you confused with installing/using this within GIMP, or using the exported .dat file in OpenSCAD?

Thanks for this externally useful plugin.

Real time-saver convert the .jpg to .png convert in GIMP to grayscale as per my previous comment. Then OpenSCAD, press F6 and Export to STL. This all took 9 minutes for start to loading into slic3r. When I started I used numerous complex processes in Inkscape which took many hours to learn to use and no real results. I changed from impress to emboss just by using Menu-> Image->Mode->Grayscale,Menu> Image-> Scale Image x=128, Menu-> Color > Invert. Menu-> Export as.. OpenSCAD .dat file. This took 2 minutes in GIMP, in Inkscape it would have ment reloading and exporting as DXF etc... Less to learn much faster with this OpenSCAD Exporter extension. Thanks

Hi I installed Gimp 2.8.14 for windows 32 bit, but did not start the program. I then downloaded and extracted the file "openscad_surface_export.py" and put it in the path C:\Program Files\GIMP 2\lib\gimp\2.0\plug-ins.
Now I started Gimp 2.8.14 for the first time, by watching the startup screen I saw the program installing lots of .py extensions in plugins directory. The new surface export extension was loaded and all I did was Menu: File> Export as.. , Selected the OpenSCAD .dat file changes the extension name at top screen to .dat and the green bar moves across screen as saving.
In GIMP the picture was scaled to 128 by 128 using Menu -> Image -> Scale Image previously and save in GIMP format before the export
Her is the first few lines from .dat file

Created by gimp plugin openscad_surface_export.py, 09/17/14 21:23:55

Name: [lenna_by_zaidot-d6ccp4i] (imported)

type: matrix

Rows: 128

Columns: 128

0.205882352941 0.205882352941 0.205882352941 0.205882352941 0.205882352941 0.205882352941 0.205882352941 0.201960784314 0.201960784314 0.201960784314 0.201960784314 0.303921568627 0.135294117647 0.150980392157 0.150980392157 0.150980392157

Trying to display in OpenSCAD became blank. This is because the SCALE command make this picture so small cannot be seen.
mirror([0, 1, 0]) {
surface(file = "lenna_by_zaidot-128.dat", convexity = 5)

This makes the emboss really deep, by increase of 8 times on z axis.
To display Design -> Reload and compile (F4)
The detail is not that great and you may need to play with the scaling to get this right.
The original code from imagemagic was in values from 158 to 249 and so needed rescaling to 0.39 and 1/256. The output from GIMP in grayscale values already 0.5 to -0.5 so does not need scaling

Having a little trouble. All values are -0.5 Have the latest Gimp and Python installed.

Note that this plugin scales values from -0.5 to 0.5 (or just under*) which might not be what you are expecting (but is not wrong). Also, it looks like openscad itself adds some kind of raft to the surface. The manual doesn't have much detail on this but something else to be borne in mind.

*Changing the calculation to (pixval-127.5)/255 would produce what one might be expecting.

Is there a way back? Using a stl-file to generate a grayscale hight map png-file?

The simplest way is to take the stl into a 3d rendering program and colour it with a black to white gradient along the Z axis. Then set up the camera directly above the surface with a non-perspective projection and render an image at the scale you want.

Thank you for the Plug-In. I tested it with Gimp 2.8.3 (OS X 10.8.3), it works.

How-to for use with Customizable Lithopane offline:

First extract the python file "http://openscad_surface_export.pyopenscad_surface_export.py" and put it in your gimp plugin folder (/Application/Gimp/Content/Resources/lib/glimp/2.0/plug-ins)

  1. Open an image in Gimp.
  2. Select <img> (right mouse click) Image -> Mode -> Grayscale.
  3. Invert Colors: Menu > Colors > Invert.
  4. Export the image with a ".dat" extension (i.e. "Surface.dat").

However it doesn't work with the latest Gimp-Version 2.8.4.

Can you be more specific other than "it doesn't work"? Are there any errors, does the file get created incorrectly, or nothing at all?

I installed the new Version 2.8.4 and the plug-in again. Now it works.
Last time the export (Menu: File>Export>"Surface.dat") failed. I got this message:
"The given filename does not have any known file extension..."

Sorry for the mistake!

Hi, I tested your plugin with Gimp 2.8.x in Linux, it doesn't work maybe with the new politic of the Saving menu (only Gimp file here).

For the newer version of GIMP, you need to use the export command, then select the .dat extension. Works great for me now. A bit of a learning curve to get it working. Awesome plugin!

Thanks Pyrophreek for your reply but it doesn't work for me.
If I force the export with the .dat extension, I get this message:
"The given filename does not have any known file extension. Please enter a known file extension or select a file format from the file format list."
The plugin is installed in the home user folder of Gimp plug-ins. (~/.gimp-2.8/plug-ins/).

I put it in C:\Program Files\GIMP 2\lib\gimp\2.0\plug-ins (windows). Haven't tried it in the other directories.

thanks for your reply.

I've just tried to put the plugin in the main folder /usr/lib/gimp/2.0/plug-ins/ but it doesn't work. The ".dat" extension is not available in the export menu.
May be, it's a problem with the linux version.

Same issue for me, maybe only works on older gimp?

Nope, i take it back. I just forgot to chmod +x file.py to make it work :D

Glad you figured out out!