Measurement tool incorrect against ruler in image by VARYING amounts
The photo has barrel distortion, so the ruler scale isn't linear. Hence the inconsistencies.
Still, you can align it to the grid.

Adjust transparency for the image, to see the grid underneath
Move the 3D cursor to 0mm markings and set it as Pivot Point (using the overlay menu)
Scale the image until the 170mm markings match the grid

(The gif starts with the ruler perfectly aligned)