/** * Returns boundings of text depending on the available font extension * * @param float $size Textsize * @param ezcGraphFontOptions $font Font * @param string $text Text * @return ezcGraphBoundings Boundings of text */ protected function getTextBoundings($size, ezcGraphFontOptions $font, $text) { switch ($font->type) { case ezcGraph::PS_FONT: if (!isset($this->psFontRessources[$font->path])) { $this->psFontRessources[$font->path] = imagePsLoadFont($font->path); } $boundings = imagePsBBox($text, $this->psFontRessources[$font->path], $size); return new ezcGraphBoundings($boundings[0], $boundings[1], $boundings[2], $boundings[3]); case ezcGraph::TTF_FONT: switch (true) { case ezcBaseFeatures::hasFunction('imageftbbox') && !$this->options->forceNativeTTF: $boundings = imageFtBBox($size, 0, $font->path, $text); return new ezcGraphBoundings($boundings[0], $boundings[1], $boundings[4], $boundings[5]); case ezcBaseFeatures::hasFunction('imagettfbbox'): $boundings = imageTtfBBox($size, 0, $font->path, $text); return new ezcGraphBoundings($boundings[0], $boundings[1], $boundings[4], $boundings[5]); } break; } }
} /**if (!file_exists($font)) $font = $_SERVER["DOCUMENT_ROOT"]."/HDWFormCaptcha/".$font; if (!file_exists($font)) $font = dirname(__FILE__)."/".$font; */ $font_size = rand($min_size, $max_size); $angle = rand(-15, 15); if (function_exists("imagettfbbox") && function_exists("imagettftext")) { $box = imagettfbbox($font_size, $angle, $font, $str); $x = (int) ($imgX - $box[4]) / 2; $y = (int) ($imgY - $box[5]) / 2; imagettftext($image, $font_size, $angle, $x, $y, $text_col, $font, $str); } else { if (function_exists("imageFtBBox") && function_exists("imageFTText")) { $box = imageFtBBox($font_size, $angle, $font, $str); $x = (int) ($imgX - $box[4]) / 2; $y = (int) ($imgY - $box[5]) / 2; imageFTText($image, $font_size, $angle, $x, $y, $text_col, $font, $str); } else { $angle = 0; $font = 6; $wf = ImageFontWidth(6) * strlen($str); $hf = ImageFontHeight(6); $x = (int) ($imgX - $wf) / 2; $y = (int) ($imgY - $hf) / 2; imagestring($image, $font, $x, $y, $str, $text_col); } } header("Content-type: image/png"); imagepng($image);