Even though I found a workaround that works for my application (generating the image first and later the accompying html page), the original problem still persists. <br><br>Just a short example of code (where the width and height are based on the extent, like in my application) and it&#39;s output. My hypothesis is that maybe the longitude/latitude values are the problem? 
<br><br>dl(&#39;php_mapscript.so&#39;);<br>$oMap = ms_newMapObj(&#39;/home/johan/rwanda/start-print.map&#39;);<br>$mapExtent = $oMap-&gt;extent;<br>$oMap-&gt;setExtent($aExtent[0],$aExtent[1],$aExtent[2],$aExtent[3]);<br>
$tot = $oMap-&gt;numlayers;<br>$pw = 600;<br>&nbsp;$gw =$aExtent[2] - $aExtent[0];<br>&nbsp;$gh = $aExtent[3] - $aExtent[1];<br>&nbsp;$ph = ceil($pw*$gh/$gw);<br>&nbsp;$oMap-&gt;set(&#39;width&#39;, $pw);<br>&nbsp;$oMap-&gt;set(&#39;height&#39;, $ph);
<br>$oMap-&gt;selectOutputFormat(&#39;PNG&#39;);<br><br>var_dump($oMap-&gt;extent);<br>$oImg = $oMap-&gt;draw();<br>var_dump($oMap-&gt;extent);<br>die;<br><br>gives the following output:<br><pre>object(ms_rect_obj)#2 (5) {
<br>  [&quot;_handle_&quot;]=&gt;<br>  resource(3) of type (Unknown)<br>  [&quot;minx&quot;]=&gt;<br>  float(29.7975484895)<br>  [&quot;miny&quot;]=&gt;<br>  float(-1.93103563105)<br>  [&quot;maxx&quot;]=&gt;<br>  float(29.9594623555
)<br>  [&quot;maxy&quot;]=&gt;<br>  float(-1.80965089289)<br>}<br>(and after the draw method is called:)<br><br>object(ms_rect_obj)#2 (5) {<br>  [&quot;_handle_&quot;]=&gt;<br>  resource(3) of type (Unknown)<br>  [&quot;minx&quot;]=&gt;
<br>  float(29.7596991183)<br>  [&quot;miny&quot;]=&gt;<br>  float(-1.93103563105)<br>  [&quot;maxx&quot;]=&gt;<br>  float(29.9973117267)<br>  [&quot;maxy&quot;]=&gt;<br>  float(-1.80965089289)<br>}<br></pre><br><div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br><br><br>2007/5/23, Johan Van de Wauw &lt;<a href="mailto:johan.vandewauw@gmail.com">johan.vandewauw@gmail.com</a>&gt;:<br>&gt; Hello everyone,<br>&gt;<br>&gt; When generating a map using mapscript, I notice that the extent changes
<br>&gt; (slightly) after calling the &quot;draw&quot; operation.<br>&gt; I don&#39;t seem to be the only one with this problem as eg the ka-map wiki<br>&gt; says:<br>&gt;<br>&gt; Print output is related to viewport but image extent correspondence in not
<br>&gt; yet perfect.<br>&gt;<br>&gt; Is there a way to make this correspondence better, or is there a way to<br>&gt; get/predict the actual extent used in the image before (or without) calling<br>&gt; the &quot;draw&quot; method?
<br>&gt;<br>&gt; Johan<br>&gt;<br></blockquote></div><br>