I keep a library of images of a stage micrometer (a microscope slide with rulings of known pitch, like a mini ruler) for combinations of ocular and objective for each of my microscopes, taken under fixed camera conditions of resolution and optical zoom (I only ever use digital zoom for focussing purposes).
Using an image editor I create a second transparent layer in each library image of the stage micrometer and create a scale bar in this layer. The image is then saved in an image format that preserves the layers. I can then copy the scale bar from the relevant layer, without the micrometer rulings, and paste it into any picture taken under the same conditions of ocular, objective, camera and camera zoom.
Here is an example from my library. Original image size is 2592 x 1944 pixels.

Microscope: Zeiss Standard GFL
Ocular: Olympus P15
Objective: Leitz x40 NPL Fluotar ICT
Camera: Canon Powershot S50
Zoom: Setting 5 (Focal length 14.7 mm)
Stage micrometer: 0.1 & 0.01 mm rulings (100 microns and 10 microns)