HTML に埋め込む ( IMG -> PHP( GD ) )


  IMG 要素の src 属性で PHP を指定する




  

<IMG
	src="http://lightbox.on.coocan.jp/php/font_php5_euc.php"
	border="0"
	galleryimg="no" />
  

↓実装サンプル


この方法も、外部から自由にアクセスできるので $_SERVER['HTTP_REFERER'] によって
アクセス制限を加える必要があるでしょう。



↓参考ページ
http://winofsql.jp/VA003334/phpVarious080113192647.htm#ttl5

mbstring.encoding_translation = On の場合は、
入力 URL エンコードされたキャラクタセットが何であれ、内部文字エンコーディングへの変換が行われます

よってその場合は、
mb_language( "ja" );
mb_internal_encoding("EUC-JP");
$img_text = mb_convert_encoding($_GET['text'],"UTF-8","EUC-JP");
で正しく動作するはずです。

しかし、
mbstring.encoding_translation = On で無い場合は( デフォルト )
入力エンコードにあわせたデコードをする必要があります

また、JavaScript から呼ばれる JavaScript の encodeURIComponent でエンコードされる
Ajax の場合は、
mb_language( "ja" );
mb_internal_encoding("EUC-JP");
$img_text = $_GET['text'];

でかまいません。

  UTF-8




通常、imagettftext が要求する文字列は、UTF-8 なので以下のサンプルでは
特に変換の必要がありませんが、ソース自体は UTF-8N で保存して下さい。



Nifty の Lacoocan の PHP5 ではおそらく PHP 自体に手が入れられているのか、
imagettftext は、EUC-JP を要求します。
DB が EUC のはずですから、問題が発生しにくい対処だと思われます。

  

<?
# **********************************************************
# このソースコードは、utf-8 で記述されています
# ( ソースそのものの形式は utf-8n です )
# **********************************************************
header("Content-type: image/png");
header( "Expires: Wed, 31 May 2000 14:59:58 GMT" );

$img_text = "日本語表示";
$font_path = "../r205/font/ArmedBanana.ttf";

# **********************************************************
# 内部コードは、EUC-JP
# **********************************************************
mb_language( "ja" );
mb_internal_encoding( "UTF-8" );

# **********************************************************
# キャンバス作成
# **********************************************************
$im = imagecreate( 150, 30 );

# ***********************************************************
# 画像の背景色
# imagecolorallocate() の最初のコールで背景色がセットされます
# ***********************************************************
$white = imagecolorallocate( $im, 255, 255, 255 );

# ***********************************************************
# 画像の文字色
# ***********************************************************
$black = imagecolorallocate( $im, 0, 0, 0 );

imagettftext(
	$im,
	20,	# サイズ
	0,	# 角度
	5,	# x 座標
	22,	# y 座標
	$black,
	$font_path,
	$img_text);

# ***********************************************************
# PNG 出力
# ***********************************************************
imagepng($im);

# ***********************************************************
# 終了処理
# ***********************************************************
imagecolordeallocate( $im, $black );
imagecolordeallocate( $im, $white );
imagedestroy($im);

?>
  

  EUC-JP

  

<?
# **********************************************************
# このソースコードは、EUC-JP で記述されています
# **********************************************************
header("Content-type: image/png");
header( "Expires: Wed, 31 May 2000 14:59:58 GMT" );

$font_path = "../r205/font/ArmedBanana.ttf";

# **********************************************************
# 内部コードは、UTF-8 ( EUC-JP でも良い )
# **********************************************************
mb_language( "ja" );
mb_internal_encoding( "UTF-8" );

# **********************************************************
# 対象文字列
# **********************************************************
$img_text = "日本語表示";
$img_text = mb_convert_encoding( $img_text, "UTF-8", "EUC-JP" );

# **********************************************************
# キャンバス作成
# **********************************************************
$im = imagecreate( 150, 30 );

# ***********************************************************
# 画像の背景色
# imagecolorallocate() の最初のコールで背景色がセットされます
# ***********************************************************
$white = imagecolorallocate( $im, 255, 255, 255 );

# ***********************************************************
# 画像の文字色
# ***********************************************************
$black = imagecolorallocate( $im, 0, 0, 0 );

imagettftext(
	$im,
	20,	# サイズ
	0,	# 角度
	5,	# x 座標
	22,	# y 座標
	$black,
	$font_path,
	$img_text);

# ***********************************************************
# PNG 出力
# ***********************************************************
imagepng($im);

# ***********************************************************
# 終了処理
# ***********************************************************
imagecolordeallocate( $im, $black );
imagecolordeallocate( $im, $white );
imagedestroy($im);

?>
  

  SHIFT_JIS

  

<?
# **********************************************************
# このソースコードは、SHIFT_JIS で記述されています
# **********************************************************
header("Content-type: image/png");
header( "Expires: Wed, 31 May 2000 14:59:58 GMT" );

$font_path = "../r205/font/ArmedBanana.ttf";

# **********************************************************
# 内部コードは、UTF-8 ( EUC-JP でも良い )
# **********************************************************
mb_language( "ja" );
mb_internal_encoding( "UTF-8" );

# **********************************************************
# 対象文字列
# **********************************************************
$img_text = "日本語表示";
$img_text = mb_convert_encoding( $img_text, "UTF-8", "SJIS" );

# **********************************************************
# キャンバス作成
# **********************************************************
$im = imagecreate( 150, 30 );

# ***********************************************************
# 画像の背景色
# imagecolorallocate() の最初のコールで背景色がセットされます
# ***********************************************************
$white = imagecolorallocate( $im, 255, 255, 255 );

# ***********************************************************
# 画像の文字色
# ***********************************************************
$black = imagecolorallocate( $im, 0, 0, 0 );

imagettftext(
	$im,
	20,	# サイズ
	0,	# 角度
	5,	# x 座標
	22,	# y 座標
	$black,
	$font_path,
	$img_text);

# ***********************************************************
# PNG 出力
# ***********************************************************
imagepng($im);

# ***********************************************************
# 終了処理
# ***********************************************************
imagecolordeallocate( $im, $black );
imagecolordeallocate( $im, $white );
imagedestroy($im);

?>
  




yahoo  google  MSDN  MSDN(us)  WinFAQ  Win Howto  tohoho  ie_DHTML  vector  wdic  辞書  天気 


[phpVarious]
CCBot/2.0 (https://commoncrawl.org/faq/)
23/12/09 07:07:01
InfoBoard Version 1.00 : Language=Perl

1 BatchHelper COMprog CommonSpec Cprog CprogBase CprogSAMPLE CprogSTD CprogSTD2 CprogWinsock Cygwin GameScript HTML HTMLcss InstallShield InstallShieldFunc JScript JScriptSAMPLE Jsfuncs LLINK OldProg OracleGold OracleSilver PRO PRObrowser PROc PROconePOINT PROcontrol PROftpclient PROjscript PROmailer PROperl PROperlCHAT PROphp PROphpLesson PROphpLesson2 PROphpLesson3 PROphpfunction PROphpfunctionArray PROphpfunctionMisc PROphpfunctionString PROsql PROvb PROvbFunction PROvbString PROvbdbmtn PROvbonepoint PROwebapp PROwin1POINT PROwinSYSTEM PROwinYOROZU PROwindows ProjectBoard RealPHP ScriptAPP ScriptMaster VBRealtime Vsfuncs a1root access accreq adsi ajax amazon argus asp aspSample aspVarious aspdotnet aw2kinst cappvariety centura ckeyword classStyle cmaterial cmbin cmdbapp cmenum cmlang cmlistbox cmstd cmstdseed cmtxt cs daz3d db dbCommon dbaccess dnettool dos download flex2 flex3 flex4 framemtn framereq freeWorld freesoft gimp ginpro giodownload google hdml home hta htmlDom ie9svg install java javaSwing javascript jetsql jquery jsp jspTest jspVarious lightbox listasp listmsapi listmsie listmsiis listmsnt listmspatch listmsscript listmsvb listmsvc memo ms msde mysql netbeans oraPlsql oracle oracleWiper oraclehelper orafunc other panoramio pear perl personal pgdojo pgdojo_cal pgdojo_holiday pgdojo_idx pgdojo_ref pgdojo_req php phpVarious phpguide plsql postgres ps r205 realC realwebapp regex rgaki ruby rule sboard sc scprint scquest sdb sdbquest seesaa setup sh_Imagick sh_canvas sh_dotnet sh_google sh_tool sh_web shadowbox shgm shjquery shvbs shweb sjscript skadai skywalker smalltech sperl sqlq src systemdoc tcpip tegaki three toolbox twitter typeface usb useXML vb vbdb vbsfunc vbsguide vbsrc vpc wcsignup webanymind webappgen webclass webparts webtool webwsh win8 winofsql wmi work wp youtube