How to generate image of specific real-world size
As @Chris G wrote in the comment:

Generating an image is pixel based. If you create an image that has a line every 300 pixels and print it at 300dpi, the lines will be exactly one inch apart. (dpi = dots per inch). You can set the dpi in Photoshop for instance, then make sure the image is printed @ 100% scaling. (in case it's not clear: the "digital distance" doesn't matter, since you can always adjust the dpi to achieve a specific millimeter distance in the printout)

For example, if I make an image of size 6*300px and 9*300px and I print it with 300dpi, it will be 6x9 inches on paper.
I need to generate image on which will be lines representing distances between frets on guitar. It is supposed to be printed later and act as mask for marking the frets. Therefore, the distances has to be precise.
How can i generate image of specific size in centimeters / milimeters, so when I print it, it will have same size?
I can use Python / JS / Java / C++