function tEXt($key, $val='')
{
$str = $key. "\0". $val;
return pack('N', strlen($str)). 'tEXt'. $str. pack('N', crc32('tEXt'. $str));
}
ob_start();
$im = imagecreate(10, 10);
imagecolorallocate($im, rand(0, 127), rand(0, 127), rand(50, 127));
$cl = imagecolorallocate($im, rand(128, 255), rand(128, 255), rand(128, 255));
imagechar($im, 5, rand(0, 2), -3, $a = chr(65 + rand(0, 25)), $cl);
$imt = imagecreatetruecolor($w=100, $h=100);
imagecopyresampled($imt, $im, 0, 0, 0, 0, 100, 100, 10, 10);
imagepng($imt);
$src = ob_get_clean();
$text = tEXt('alt', $a). tEXt('height', $h). tEXt('width', $w);
$iend = hex2bin('0000000049454e44ae426082');
$src = str_replace($iend, $text. $iend, $src);
imagedestroy($im);
?>
<img src="data:image/png;base64,<?=base64_encode($src)?>" alt="<?=$a?>" height="<?=$h?>" width="<?=$w?>">
出力
確認
identify -verbose *.png
スクリンショット