So the pixel resolution of a given tile should be 360/256^Zoom.
If you divide the size of the static image (400 in the example) by the size of the bounding box, you should get your expected resolution, then it's just a matter of determining the closest zoom level.
This assumes your bounding box is in decimal degrees, the equation becomes a little more complicated if you are working in a metered projection.
So the pixel resolution of a given tile should be 360/256^Zoom.
If you divide the size of the static image (400 in the example) by the size of the bounding box, you should get your expected resolution, then it's just a matter of determining the closest zoom level.
This assumes your bounding box is in decimal degrees, the equation becomes a little more complicated if you are working in a metered projection.
If I did the math correctly (and I'm uncaffeinated for 9 days, so no promises) this equation should be:
_zoom = @log(360*@Value(_size)/(@Value(_xmax)-@Value(_xmin)))/@log(2) - 8
where _size is the output image size (400 in the example)