GD作成

phpで画像に文字を打ち出す関数GDです。下記のphpファイルをイメージとして出力するだけというか

1
<img src ="gd.php"/>

として配置するだけです。


スポンサーリンク

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
gd.php
<?php
// 空の画像を作成し、テキストを追加します
 
//ランダムな数字
$number = mt_rand(10000,99999);
 
//画像の作成
$im = imagecreatetruecolor(200, 50);
 
//色の作成(背景色)
$backcol = imagecolorallocate($im, 255, 255, 255);
 
//背景色を塗る
imagefilledrectangle($im, 0, 0, 200, 50, $backcol);
 
//色の作成(文字)
$text_color = imagecolorallocate($im, 255, 0, 0);
 
//文字を書く
imagestring($im, 2, 10, 10,"{$number}", $text_color);
 
// content type ヘッダを、ここでは image/png と設定します
header("Content-type: image/png");
 
// 画像を出力します
imagepng($im);
 
// メモリを開放します
imagedestroy($im);
?>

デモサイト

Pocket
LINEで送る

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です