WHAT? gta2 supports unicode (or wtf is it if its more than 256)? no way... o_O
added textarea and transparency with epic background texture (not "burn" in the image).
Code: Select all
<?php
// set headers:
header("Content-type: image/png");
if($_GET['text'] == ""){
$text = "usage: ?text=something";
}else{
$text = $_GET['text'];
}
$text = trim($text); // remove extra whitespace like newlines etc from start/end.
$font_height = 25; // normal font height.
$poswidth = array(0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0,
0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,9, 9,6, 15,11, 0,0, 26,12, 38,11, 0,0,
49,6, 55,9, 64,9, 73,12, 0,0, 85,6, 91,11, 102,6, 108,12, 120,12, 132,9, 141,12, 153,12, 165,13, 178,12, 190,12,
202,12, 214,12, 226,12, 238,6, 244,6, 0,0, 0,0, 0,0, 250,11, 261,6, 267,11, 278,11, 289,11, 300,11, 311,11,
322,11, 333,11, 344,11, 355,8, 363,12, 375,13, 388,11, 399,16, 415,11, 426,11, 437,11, 448,11, 459,11, 470,11,
481,10, 491,11, 502,12, 514,16, 530,11, 541,12, 553,10, 0,0, 0,0, 0,0, 0,0, 563,11, 0,0, 574,11, 585,11, 596,11,
607,11, 618,11, 629,11, 640,11, 651,11, 662,6, 668,8, 676,13, 689,6, 695,16, 711,11, 722,11, 733,11, 744,11,
755,11, 766,11, 777,9, 786,11, 797,12, 809,16, 825,12, 837,11, 848,10, 0,0, 0,0, 0,0, 858,13, 0,0, 0,0, 0,0,
0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0,
0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0,
0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 871,11, 882,11, 893,11,
904,11, 0,0, 915,11, 0,0, 926,16, 942,11, 953,11, 964,11, 975,11, 986,11, 997,9, 1006,9, 1015,11, 1026,10, 0,0,
1036,11, 1047,11, 1058,11, 1069,11, 0,0, 1080,11, 0,0, 0,0, 1091,11, 1102,11, 1113,11, 1124,11, 0,0, 0,0,
1135,12, 1147,11, 1158,11, 1169,11, 0,0, 1180,11, 0,0, 1191,17, 1208,11, 1219,11, 1230,11, 1241,11, 1252,11,
1263,8, 1271,8, 1279,10, 1289,10, 0,0, 1299,11, 1310,11, 1321,11, 1332,11, 0,0, 1343,11, 0,0, 0,0, 1354,11,
1365,11, 1376,11, 1387,11, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 1398,12, 1410,12, 1422,12, 1434,12, 0,0, 0,0, 0,0,
0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 1446,12, 1458,12, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0,
0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0,
0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 1470,12, 1482,7, 1489,12, 1501,12, 0,0, 0,0, 0,0, 0,0,
0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 1513,12, 1525,12, 0,0, 0,0,
0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0,
0,0, 0,0, 0,0, 0,0, 0,0, 1537,11, 1548,11, 1559,11, 1570,11, 0,0, 0,0, 0,0, 0,0);
// calculate resulting image size:
$width = 0; // resulting image sizes will be set to these,
$height = 0;
$xpos = 0; // currently looped chars pixel positions,
$ypos = 0;
$len = strlen($text);
for($p = 0; $p < $len; $p++){
$val = ord($text[$p]); // get char numeric value.
$charwidth = $poswidth[$val*2+1];
// process newlines:
if($text[$p] == "\n"){
$ypos += $font_height;
$xpos = 0;
}
if($charwidth == 0){
continue; // skip chars that cant be rendered.
}
$xpos += $charwidth;
// find max image width (added $charwidth previously):
if($xpos > $width){
$width = $xpos;
}
}
$height = $ypos+$font_height; // add $font_height here because there is no last "\n" char (was trimmed).
// load font:
$font = imagecreatefrompng("gta2font_normal.png");
imagealphablending($font, true);
// render image:
$im = imagecreatetruecolor($width, $height);
imagealphablending($im, false);
imagesavealpha($im, true);
$bgcolor = imagecolorallocatealpha($im, 239,239,239, 127); // 127 = full transparency.
imagefilledrectangle($im, 0, 0, $width, $height, $bgcolor);
$xpos = 0;
$ypos = 0;
for($p = 0; $p < $len; $p++){
$val = ord($text[$p]); // get char numeric value.
$charwidth = $poswidth[$val*2+1];
// process newlines:
if($text[$p] == "\n"){
$ypos += $font_height;
$xpos = 0;
}
if($charwidth == 0){
continue; // skip chars that cant be rendered.
}
$charpos = $poswidth[$val*2];
imagecopy($im, $font, $xpos, $ypos, $charpos, 0, $charwidth, $font_height);
$xpos += $charwidth;
// find max image width (added $charwidth previously):
if($xpos > $width){
$width = $xpos;
}
}
imagepng($im); // output PNG image
// free resources:
imagedestroy($im);
imagedestroy($font);
?>
did some code tests to see what crashed this page with syntax highlighter.... seems like array() cant have more than ~400 elements in it