画像データをテキスト形式で表示


サンプル

<?php
	// 100×100の画像リソースを作成
	$im =  imagecreatetruecolor(100, 100);
 
	// 白色を作成
	$white = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
 
	// ブレンドモードを無効
	imagealphablending($im, false);
	// 背景色を描画する
	imagefilledrectangle($im, 0, 0, 100, 100, $white);
 
	// 色インデックスを作成
	$red = imagecolorresolvealpha($im, 255, 50, 0, 50);
	$red2 = imagecolorresolvealpha($im, 0, 150, 200, 50);
 
	// 短形を描画する
	imagefilledrectangle($im, 40, 40, 80, 80, $red);
 
	// 破線を描画するためのスタイルを設定
	$style = array($red2, $red2, $red2, $white, $white, $white);
	imagesetstyle($im, $style);
 
	// 短形を描画
	imagefilledrectangle($im, 20, 20, 40, 40, IMG_COLOR_STYLED);
?>
<html>
<body style="background-color: #000000;font-size: 6px;">
<?php
	// 画像の幅を取得
	$dx = imagesx($im);
	// 画像の高さを取得
	$dy = imagesy($im);
 
	for($y=0;$y < $dy;$y++){
		for($x=0;$x < $dx;$x++){
			$col = imagecolorat($im, $x, $y);	// ピクセルのカラーインデックスを取得
			$rgb = imagecolorsforindex($im, $col);	// カラーインデックスからカラーを取得
			printf("<span style=\"color: #%02x%02x%02x\">#</span>", $rgb['red'], $rgb['green'], $rgb['blue']);
		}
		echo "<br />";
	}
	// 画像リソースを破棄
	imagedestroy($im);
?>
</body>
</html>
 
 

イメージ(元にした画像)


イメージ(テキスト化したらこんなになった)



最終更新:2012年08月18日 23:37