Using echo-planar imaging, we developed an automated image-based procedure to shim the static (B0) field. Our method uses the rapid acquisition capability of echo-planar imaging to collect the required frequency data rapidly, rendering the shim data acquisition time negligible in comparison with the total study time. We address image distortion issues involved in echo-planar imaging acquisition of the data and formulate analytic methods for arriving at an optimal shim for the NMR imaging experiment in a single iteration. We investigated the use of cost functions other than least-squares (Chebychev, high-order numeric) and found that choice between the cost functions we tested was irrelevant to resultant image quality, at least when used in conjunction with low-order shims. With appropriate integration, the method has become routine practice for investigators at our laboratory.