public function getWidth($aImg) { $scaling = 1; //$this->iAntiAlias ? 2 : 1 ; if ($this->iSize > 0 && $this->iSize < 1) { $this->iSize *= min($aImg->width, $aImg->height); } $value = new Text\Text(); $value->SetFont($this->iFontFamily, $this->iFontStyle, $this->iFontSize * $scaling); $value->SetColor($this->iFontColor); // Setup extra size around the graph needed so that the labels // doesn't get cut. For this we need to find the largest label. // The code below gives a possible a little to large margin. The // really, really proper way would be to account for what angle // the label are at $n = count($this->iLabels); if ($n > 0) { $maxh = 0; $maxw = 0; foreach ($this->iLabels as $key => $lbl) { $value->Set($lbl); $maxw = max($maxw, $value->GetWidth($aImg)); } } else { $value->Set('888.888'); // Dummy value to get width/height $maxw = $value->GetWidth($aImg); } // Add an extra margin of 50% the font size $maxw += round($this->iFontSize * $scaling * 0.4); $valxmarg = 1.5 * $maxw + 2 * $this->iLabelMargin * $scaling; $w = round($this->iSize * $scaling + $valxmarg); // Make sure that the width of the legend fits $legendwidth = $this->_StrokeLegend($aImg, 0, 0, $scaling, true) + 10 * $scaling; $w = max($w, $legendwidth); return $w; }