The spacing of the frets depends solely on the scale length of the guitar - which is easiest to understand if you think of it as being the distance between the nut and the saddle. The nut is the slotted piece that is located at the base of the headstock and establishes the string spacing at that end of the guitar neck. The saddle is located next to the bridge on the body of the guitar, and is what the strings pass over after being secured at the bridge by the ball ends of the strings (in the case of steel string guitar - nylon strings are usually tied to the bridge before passing over the saddle). The distance between the nut and saddle equals the length of the portion of the guitar string that vibrates to make sound. It does not matter how long the guitar string is in total, the only part that matters is the part between the nut and saddle.
In the picture you included in your question, the scale length of the guitar pictured is indicated by the red line labeled # 1.
Your picture illustrates the fact that the fret spacing gets shorter as you get closer to the bridge. If you were to put a capo on a guitar and then retune the guitar to standard tuning with the capo in place, you would in effect be shortening the scale. The fret the capo is behind becomes the new "nut" in effect. The new "first fret" after the capo will have a shorter space between the new "nut" and the new "first fret" than exist between the nut and the first fret on the guitar without the capo.
Different guitars even by the same maker will often have different scale lengths from model to model and a corresponding adjustment must be made to the spacing between frets.
If the spacing is not precise between frets, the guitar will not play in tune on all frets. Some guitars have adjustable saddles which permit fine adjustments to the intonation to compensate for varying tuning characteristics of the particular guitar strings used - which can vary based on the type metal alloy the strings are made of and the diameter of the string.
Most saddles on acoustic guitars are "compensated" meaning they create a slightly different distance between point of contact at the saddle and the nut to compensate for the tuning differences between the larger diameter strings and smaller diameter strings. But the frets are always perpendicular to the fretboard and the spacing between frets is always based on the overall scale.
Technically a guitars scale is the distance between the nut and the center of the 12th fret doubled. The 12th fret is (for practical purposes) the midpoint between the nut and saddle. Therefore, the distance between the nut and 12th fret would mandate the location of the saddle and the fret spacing would be calculated based on the scale length using Pythagoras Ratios (a mathematical calculation). The Pythagoras ratios determine how the length of a guitar string (as altered by each fret) corresponds to the relative difference in pitch of the same string at each different length. For example, we know that halving the length of a guitar string (12th fret) will cause it to vibrate at a frequency which we will hear as the same note exactly one octave higher. The other divisions are more complicated than dividing by two - but each ratio will have a specific effect on the relative vibration frequency (and thus pitch) of the strings.
For a more detailed explanation of how fret spacing is calculated you may click this link Math for Guitar Fret Spacing