title: Calculate the scale given a bounding box and the width and the height of a image
body: <p>I need to calculate the scale given a bounding box in map coordinates (EPSG:900913) and the width/height of the image.</p>
  
  <p>This is becose Im implementing a very basic WMS server but in certain moments i need to know the scale of the image.</p>
  
  <p>A simple request would be : </p>
  
  <pre><code>  wms.exe?LAYERS=all&amp;SERVICE=WMS&amp;VERSION=1.1.1&amp;REQUEST=GetMap&amp;STYLES=&amp;FORMAT=image%2Fjpeg&amp;SRS=EPSG%3A900913&amp;BBOX=-7810029.800979,-2298920.0623849,-7809724.0528659,-2298614.3142718&amp;WIDTH=256&amp;HEIGHT=256
  </code></pre>
  
  <p>that request is originated from a openlayer component in a web page configured with this parameters :</p>
  
  <pre><code>var optionsGmap = {
  projection: new OpenLayers.Projection("EPSG:900913"),
  units: "m",
  sphericalMercator: true,
  numZoomLevels: 16,
  maxExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34, 20037508.34, 20037508.34),
  scales : [110936068.185464,55468034.0927321,27734017.0463661,13867008.523183,6933504.26159152,
      3466752.13079576,1733376.06539788,866688.03269894,433344.01634947,216672.008174735,108336.004087367,54168.0020436837,27084.0010218419,
      13542.0005109209,6771.00025546046,3385.50012773023],
  maxResolution: "auto" };
  </code></pre>
  
  <p>theres formula to calculate this? I have access to a postgres+posgis in the backend but I prefer to do the calculation by my self in C code.</p>