Generating normal map

Hello, I’d like to know how to generate normal map for a particular image. I know there’s texture tool for adobe photoshop. I’d like to write code that can be used to generate normal maps for image.

You cannot generate a normal map from a regular texture.

To be more specific: a normal map enclodes slope and facing information, and this information just does not exist in a regular texture. You need a height map or a bump map (or even a high-polygon model) to generate a normal map properly.

Tools do exist that claim to generate a normal map from a regular texture, but they’re all just hacks and approximations. They might even look OK, at least until you understand what it is you’re looking at.