I have many many .png files and I'm looking for a way to generate height maps (or normal maps) for each of them. I can get the result I want from the gimp normalmap plugin but I need a way to automate the process or an alternative tool. I don't know enough about the underlying algorithms to reproduce them, and very little about cg in general. Is there a library or tool that will do this? I'm not picky about the language as long as the api/interface is high-level enough, though open source is preferable as I don't have access to fancy software at the moment. Thanks!
1 Answers
You can jsut script GIMP itself for that. I don't know which plug-in you are calling 'normalmap' - or what you mean by 'height map' (height maps I know are just the grayscale version of the image) - but even if it is a third party plug-in, it should be possible to run it through the scripting interface.
Just go to plug-ins-> Python-FU->console
- you will be dropped to a Python prompt. Click on the "browse" button - then locate the plug-on you want to call. If you click "apply" - the browser will paste a template for the plug-in call to the Python prompt.
SO, prior to doing that, you may want to test the call: open a sample image, go to the Python prompt, and get a reference to the image by typing:
image = gimp.image_list()[0]
, then get a reference to the first layer of the image typing drawable = image.layers[0]
.
These should be all the data the call for your plug-in would need to be pre-created. Do as above to paste a call to your desired plug-in on the prompt. Note that the names image
and drawable
above are just variable names - you may chooseyour own - but these are the names that are usually pre-filled in when you pick "apply" from the "Browse" button for a procedure call.
Once you get it working up to here, you can leverage on Python to open all images in a folder, apply the plug-in, and save them back - you can typ e this directly on the console, or later, create a plug-in that will show up in the menus.
import os
for filename in os.listdir('mydir'):
if not filename.endswith('.png'): continue
name = 'mydir/' + filename
image = pdb.gimp_file_load(name, name)
pdb.plug_in_bump_map(......) # use your plug-in here
outputname = 'mydir/' + name.split('.')[0] + '_normal.png'
pdb.gimp_file_save(image, image.layers[0], outputname, outputname)
pdb.gimp_image_delete(image) # just frees the image from memory.
Just press twice and the sequence will be run for an entire folder. (Note that if you want to run the "bump-map" plug-in there are several parameters that have to be replaced from variable names to the actual values you want).
If that is what you want, and you will be using it a lot, save it as a .py file, and put that code inside a proper function to turn it into a plug-in - there is a fill examplee for that in my answer here:
-
Thank you, also for realizing what I actually needed :) – calopter Nov 02 '16 at 09:12