<?php // -*- coding: utf-8 -*- define('TTF', '/tmp/shuowen.ttf'); //フォントファイル define('OUTIMG', '/tmp/img'); //画像出力先dir mb_regex_encoding('UTF-8'); mb_internal_encoding("UTF-8"); outPNG(OUTIMG, TTF, '幸', '496b-80'); /** * 文字画像出力 **/ function outPNG($dir, $font, $text, $name) { $width = 80; $height = 90; $fontSize = 60; $fangle = 0; $img = imagecreate($width, $height); $black = ImageColorAllocate($img, 0x0, 0x0, 0x0); $white = ImageColorAllocate($img, 0xff, 0xff, 0xff); //imagealphablending($img, true); //imagesavealpha($img, true); ImageFilledRectangle($img, 0, 0, $width, $height, $white); imagecolortransparent($img, $white); $box = imagettfbbox($fontSize, 0, $font, $text); $x = 0; $y = 70; imageTTFText($img, $fontSize, $fangle, $x, $y, $black, $font, $text); $filename = $dir . "/" . $name . ".png";
$title = trim($title) . " " . trim($title->duan_note); } if ($chapid == "v29") { break; } outChap($mode, $chapid, trim($title)); foreach ($chapter->shuowen as $shuo) { foreach ($shuo->one as $one) { if (count($one->wordhead) < 1) { continue; } $id = trim($one->wordhead['id']); $img = trim($one->wordhead['img']); $ch = mb_ereg_replace('(.*)', '', trim($one->wordhead)); // 文字のパーツは全角まるカッコでくくられている $parts = mb_ereg_replace("{$ch}", '', trim($one->wordhead)); $parts = mb_ereg_replace("[()]", '', $parts); $bun = ""; for ($i = 0; $i < count($one->explanation); $i++) { $bun = $bun . "【" . trim($one->explanation[$i]) . "】\n"; $bun = $bun . trim($one->duan_note[$i]) . "\n"; } outBun($mode, $chapid, $id, $img, $ch, $parts, trim($bun)); if ($outPNG > 0) { outPNG($pngOutDir, $fontfile, $ch, $img); } // echo "$pngOutDir, $fontfile, $ch, $img \n"; //exit; } } }