Добрый вечер! Такая проблема, изначатьно есть шрифт *.odt функцией imagettftext он мапился на картинку и всё было нормально пока не возникла необходимость использовать русские буквы. Вместо русских букв -- квадраты. Сконвертировал шрифт в *.ttf -- безрезультатно. Нужен шрифт -- dinprobold Подскажите как быть?
PHP: <?php // utf 8 document $ttf_font = "your/dir/ARIAL.TTF"; $winstring = "проверка"; //utf8 string header("Content-type: image/jpeg"); $im = ImageCreate(400,30); $black = ImageColorAllocate($im, 0,0,0); $white = ImageColorAllocate($im, 255,255,255); ImageFill($im, 0, 0, $white); ImageTTFText($im, 18, 0, 10, 20, $black, $ttf_font, $winstring); ImageJpeg($im); это работает у вас?
Такой код PHP: <?php class DrawText { public $jpegQuality = 100; private $ttfFont = false; private $ttfFontSize = false; private $hImage = false; private $hColor = false; public function __construct($imagePath) { if (!is_file($imagePath) || !list(,,$type) = @getimagesize($imagePath)) return false; $this->hImage = @imagecreatefromjpeg($imagePath); } public function __destruct() { if ($this->hImage) imagedestroy($this->hImage); } public function setFont($font, $size, $color, $alpha) { if ( !is_file($font) ) { return false; } #echo '$color: '.$color; $this->ttfFont = $font; $this->ttfFontSize = $size; if ($color) $this->setColor($color, $alpha); } public function putText($x, $y, $text, $angle = 0) { if (!$this->ttfFont || !$this->hImage || !$this->hColor) return false; imagettftext( $this->hImage, $this->ttfFontSize, $angle, $x, $y + $this->ttfFontSize, $this->hColor, $this->ttfFont, $text); } public function setColor($color, $alpha) { if (!$this->hImage) return false; list($r, $g, $b) = array_map('hexdec', str_split(ltrim($color, '#'), 2)); #return $alpha === false ? return $this->hColor = imagecolorallocate($this->hImage, $r+1, $g+1, $b+1); #: #$this->hColor = imagecolorallocatealpha($this->hImage, $r+1, $g+1, $b+1, $alpha); } public function output ($target, $replace = true) { if (is_file ($target) && !$replace) return false; $ext = strtolower(substr($target, strrpos($target, ".") + 1)); switch ($ext) { case "jpg" : case "jpeg": imagejpeg($this->hImage, $target, $this->jpegQuality); break; default: return false; } return true; } } # CLASS $pictureName = "1.jpg"; $picture = new DrawText($pictureName); $transparency = 100; #$font = "arial.ttf"; $font = "dinprobold.ttf"; $textSize = "20"; $textColor = "#123"; $text = "Test --> Тест"; $x = 22; $y = 22; $picture -> setFont('fonts/'.$font, $textSize, $textColor, $transparency); $picture -> putText($x, $y, $text); $tmpFileName = "2.jpg"; $picture -> output($tmpFileName); header('Location: [url=http://'.$_SERVER]http://'.$_SERVER[/url]["SERVER_NAME"].'/2.jpg'); ?>
Удивительно, у меня работает. Попробуй в браузере поставить кодировку utf8 и эхнуть $text. что выдает?
Что за бред, при чем тут апач. Русский текст в скрипте, значит все дело в кодировке, в которой сохранен скрипт. Она не совпадает с кодировкой шрифта. Надо или сохранить скрипт в другой кодировке, или взять другой шрифт.