目次 |
---|
・PHPで画像を作成する ・背景色を指定する ・画像に文字を出力する ・画像を保存する |
<?php //画像作成 $img = imagecreatetruecolor(100, 40); //画像出力 header("Content-type: image/png"); header("Cache-control: no-cache"); imagepng($img); //メモリ解放 imagedestroy($img); ?>
<?php //画像作成 $img = imagecreatetruecolor(100, 40); //背景色設定 $backcol = imagecolorallocate($img, 220, 220, 220); //背景色を塗る imagefilledrectangle($img, 0, 0, 100, 40, $backcol); //画像出力 header("Content-type: image/png"); header("Cache-control: no-cache"); imagepng($img); //メモリ解放 imagedestroy($img); ?>
<?php //画像作成 $img = imagecreatetruecolor(100, 40); //背景色設定 $backcol = imagecolorallocate($img, 220, 220, 220); //背景色を塗る imagefilledrectangle($img, 0, 0, 100, 40, $backcol); //文字色設定 $strcol = imagecolorallocate($img, 0, 0, 0); //文字を書く imagestring($img, 3, 15, 15, 'testPNG', $strcol); //画像出力 header("Content-type: image/png"); header("Cache-control: no-cache"); imagepng($img); //メモリ解放 imagedestroy($img); ?>
<?php # imagepng($img); imagepng($img,'sample.png'); ?>