GTA2 Font Topic - TXT2GTA2 (Version 3 Released!)

Anything to do with GTA1/GTA2 modding (tools, scripts and more).
User avatar
Gustavob
Immortal
Posts: 407
Joined: 18 May 2009, 21:40
GH nick: Gustavob
|Gustavob|
Location: Nowhere.
Contact:

Re: GTA2 Font Topic - TXT2GTA2 (Version 3 Released!)

Post by Gustavob »

Pyro wrote:Interesting.

I know it's not complete but it seems the colour options don't seem to do anything yet? Guessing that's coming in future...
Neither do the background options. +1 for "coming in the future"
You just lost the game.
User avatar
T.M.
Immortal
Posts: 960
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: GTA2 Font Topic - TXT2GTA2 (Version 3 Released!)

Post by T.M. »

Yeah not done yet. Im doing the coloring atm.

Edit: works:
Image

Code:
generate_colors.php:
[php]<?php

$img = imagecreatefrompng("r.png");

$count = 18;
$sx = 2;
$sy = 6;
$step = 9;

$xpos = $sx;

$colors = array();
for($u = 0; $u < $count; $u++){
$color_border = imagecolorat($img, $xpos-1, $sy);
$color_high = imagecolorat($img, $xpos, $sy);
$color_high_mix = imagecolorat($img, $xpos+1, $sy);
$color_main = imagecolorat($img, $xpos, $sy+1);
$colors[] = array($color_border, $color_main, $color_high, $color_high_mix);
$xpos += $step;
}
imagedestroy($img);

for($u = 1; $u < $count; $u++){
$img = imagecreatefrompng("gta2font_normal.png");
imagesavealpha($img, true);
$width = imagesx($img);
$height = imagesy($img);

for($y = 0; $y < $height; $y++){
for($x = 0; $x < $width; $x++){
$color = imagecolorat($img, $x, $y);
if($color == $colors[0][0]){
imagesetpixel($img, $x, $y, $colors[$u][0]);
}else if($color == $colors[0][1]){
imagesetpixel($img, $x, $y, $colors[$u][1]);
}else if($color == $colors[0][2]){
imagesetpixel($img, $x, $y, $colors[$u][2]);
}else if($color == $colors[0][3]){
imagesetpixel($img, $x, $y, $colors[$u][3]);
}
}
}
imagepng($img, "gta2font_normal_c{$u}.png");
imagedestroy($img);
}

?>[/php]

gta2text.php (replace the normal font loader):
[php]
// load font (and get $font_height at same time):
if($font_style == 0 && $color_style > 0 && $color_style < 18){
$fnt = imagecreatefrompng("gta2font_normal_c{$color_style}.png");
}else{
$fnt = imagecreatefrompng("gta2font_{$typestr}.png");
}[/php]
User avatar
T.M.
Immortal
Posts: 960
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: GTA2 Font Topic - TXT2GTA2 (Version 3 Released!)

Post by T.M. »

Color codes work now:
Image

Code: Select all

This [17]EPIC [16]coloring [15]does [14]indeed
[13]seem to [12]maybe [11]work [10]correctly [9]here
it [8]must be [7]tested [6]to be sure
[5]about the [4]fact that [3]it might
[2]not work [1]correctly at all [3]!?
http://epicgta2.omnitude.net/gta2text/? ... 3%5D%21%3F

Damn firefox messes up the URL's, how can i make it to disable "user friendly" URL's? it makes it impossible to copypaste URL ! (i had to go to IE to get correct URL...)
User avatar
Cuban-Pete
Immortal
Posts: 909
Joined: 29 Jan 2010, 15:03
GH nick: Cuban-Pete

Re: GTA2 Font Topic - TXT2GTA2 (Version 3 Released!)

Post by Cuban-Pete »

Wow, nice work! I found the bug for the text image not showing up on xampp lite. It complains that the index is out "of range" (not correct) which caused the image source to be corrupt, my fix is this:

[mis]//test if the font, color or bg are set. if not, give it an existing zero
if (isset($_GET['font'])) {
$font_style = ((int)$_GET['font'])-1;
} else {
$font_style = 0;
}

if (isset($_GET['color'])) {
$color_style = ((int)$_GET['color']);
} else {
$color_style = 0;
}

if (isset($_GET['bg'])) {
$bg_style = ((int)$_GET['bg']);
} else {
$bg_style = 0;
}[/mis]

Comment on the coloring: When using a colortag higher than 18 it should not display it.

[mis]if ($color > 18) dontDisplay();

function dontDisplay(){
//do nothing!
}[/mis]
"Mmmm, your eyes are so beautiful."
User avatar
T.M.
Immortal
Posts: 960
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: GTA2 Font Topic - TXT2GTA2 (Version 3 Released!)

Post by T.M. »

That out of range error can be disabled by setting this on gta2text.php and index.php at first line of PHP code:

Code: Select all

error_reporting(E_ALL ^ E_NOTICE);
Comment on the coloring: When using a colortag higher than 18 it should not display it.
Hmm, you are right, also i found weird bug... image breaks if i use higher than 18 o_O fixing...
User avatar
T.M.
Immortal
Posts: 960
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: GTA2 Font Topic - TXT2GTA2 (Version 3 Released!)

Post by T.M. »

Fixed now. I wont make it hide the incorrect color tags, so the user can see whats wrong.
Example:
Image

the font would render the [ and ] marks if there was such marks in the font! but it doesnt, so it only shows the numbers... maybe i should convert those incorrect tags into ( and ) marks?
User avatar
Cuban-Pete
Immortal
Posts: 909
Joined: 29 Jan 2010, 15:03
GH nick: Cuban-Pete

Re: GTA2 Font Topic - TXT2GTA2 (Version 3 Released!)

Post by Cuban-Pete »

T.M. wrote:That out of range error can be disabled by setting this on gta2text.php and index.php at first line of PHP code:

Code: Select all

error_reporting(E_ALL ^ E_NOTICE);
But isn't that suppressing an error?
T.M. wrote:Fixed now. I wont make it hide the incorrect color tags, so the user can see whats wrong.
Example:
Image

the font would render the [ and ] marks if there was such marks in the font! but it doesnt, so it only shows the numbers... maybe i should convert those incorrect tags into ( and ) marks?
I would say, there is no "[" and "]" sign in the real gta2 font, so it will never show up - neither be replaced by a different sign suddenly if you typed wrong. I much rather have a small comment somewhere on the webpage saying "You entered a wrong colour-tag at line x".

//edit. which is probably a lot of work, so never mind that
"Mmmm, your eyes are so beautiful."
User avatar
Cuban-Pete
Immortal
Posts: 909
Joined: 29 Jan 2010, 15:03
GH nick: Cuban-Pete

Re: GTA2 Font Topic - TXT2GTA2 (Version 3 Released!)

Post by Cuban-Pete »

Should we put a cap on the max length (and height)? I mean, nobody is ever going to make such a long image in normal use (see below).

Image

cap at 1920 pixels?? HD screensize?
"Mmmm, your eyes are so beautiful."
User avatar
T.M.
Immortal
Posts: 960
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: GTA2 Font Topic - TXT2GTA2 (Version 3 Released!)

Post by T.M. »

But isn't that suppressing an error?
Nope, its suppresing a notice. I hate to code like this:

Code: Select all

if(isset($_GET['lol']) && $_GET['lol'] != "")
instead of just:

Code: Select all

if($_GET['lol'] != "")
And that "E_ALL ^ E_NOTICE" is PHP default it says. your server is bitch about errors, not all servers have same bitchyness level. :D
//edit. which is probably a lot of work, so never mind that
Hmm, shouldnt be that much work actually, just call the render render_gta2text() in the index.php as well and set a global var inside that loop if a code was incorrect.
Should we put a cap on the max length (and height)? I mean, nobody is ever going to make such a long image in normal use (see below).
INDEED!!! i thought of it. i will add forced newlines there for too long texts, and limit the height of total image as well.
cap at 1920 pixels?? HD screensize?
I think 640 pixels wide is enough? (as gta2 is too).
User avatar
T.M.
Immortal
Posts: 960
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: GTA2 Font Topic - TXT2GTA2 (Version 3 Released!)

Post by T.M. »

Fixed too wide images now. TODO: height limit. brb. afk for a while.
User avatar
Cuban-Pete
Immortal
Posts: 909
Joined: 29 Jan 2010, 15:03
GH nick: Cuban-Pete

Re: GTA2 Font Topic - TXT2GTA2 (Version 3 Released!)

Post by Cuban-Pete »

Yeah 640 is probably enough. Maybe put the variable that determines this at the top of the code with a little info, so if Sektor or somebody else takes over the code they can change that to their desire. :)
"Mmmm, your eyes are so beautiful."
User avatar
Gustavob
Immortal
Posts: 407
Joined: 18 May 2009, 21:40
GH nick: Gustavob
|Gustavob|
Location: Nowhere.
Contact:

Re: GTA2 Font Topic - TXT2GTA2 (Version 3 Released!)

Post by Gustavob »

Felt like doing it:
Image


Nice work guys
You just lost the game.
User avatar
T.M.
Immortal
Posts: 960
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: GTA2 Font Topic - TXT2GTA2 (Version 3 Released!)

Post by T.M. »

Cuban-Pete wrote:Yeah 640 is probably enough. Maybe put the variable that determines this at the top of the code with a little info, so if Sektor or somebody else takes over the code they can change that to their desire. :)
Yeah of course ;)

Added height limit:
Image

Image

Image

Image
User avatar
T.M.
Immortal
Posts: 960
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: GTA2 Font Topic - TXT2GTA2 (Version 3 Released!)

Post by T.M. »

TODO: 256 palette optimization, should make all images 2x smaller in filesize according to my tests!

it doesnt even matter if you use colored text with all possible colors; total amount of colors is 55 in such an image!
User avatar
Cuban-Pete
Immortal
Posts: 909
Joined: 29 Jan 2010, 15:03
GH nick: Cuban-Pete

Re: GTA2 Font Topic - TXT2GTA2 (Version 3 Released!)

Post by Cuban-Pete »

T.M. wrote:TODO: 256 palette optimization, should make all images 2x smaller in filesize according to my tests!

it doesnt even matter if you use colored text with all possible colors; total amount of colors is 55 in such an image!
also with background? still sounds like a good idea for normal font. [sm-42]
"Mmmm, your eyes are so beautiful."
User avatar
T.M.
Immortal
Posts: 960
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: GTA2 Font Topic - TXT2GTA2 (Version 3 Released!)

Post by T.M. »

I made the default color to same style as the others; removed "shininess" from it. default is off. Then i added option to enable shininess for all colors:

Image - - - - Image

Can you see the difference?

--

I will add backgrounds soon.
User avatar
Cuban-Pete
Immortal
Posts: 909
Joined: 29 Jan 2010, 15:03
GH nick: Cuban-Pete

Re: GTA2 Font Topic - TXT2GTA2 (Version 3 Released!)

Post by Cuban-Pete »

Yes I do, but it is not super clear, also depending on colour. But isn't shiny the basic style (used in GTA2)? I kinda prefer shiny one. :)

I'm not sure if you are a fan of optimization, but I was thinking about it for a little and the follow idea. Is it perhaps a good idea to make an image with most used words in English (or perhaps other languages) and do a "pre-text-scan" before copying letters. This way words like "and", "or" etc can be added quicker and speeding up generation time of images and lowering CPU usage of the server. Of course there is no need for this optimization if the text is only 5-10 letters long (or something like that), but for the longer ones it might speed up. The size of this image with often used words is also important, because an image that is too large will only slow things down.

Another idea on optimization is that the php script is made such a way that it should NOT have to reload the "base" image(s) every time and just keep them in memory to lower amount of disk reads on the server.
"Mmmm, your eyes are so beautiful."
User avatar
T.M.
Immortal
Posts: 960
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: GTA2 Font Topic - TXT2GTA2 (Version 3 Released!)

Post by T.M. »

Such optimization would be pointless; i've made before normal text renderer with 12px font, and i was able to generate like 2000x20000 size image full of text in the same speed i loaded that same text in text format :D and the method was probably even crappier than what i use here, still, the point is: i used much more calls to imagecopy() function, which you are supposed to optimize. its true that PHP function calls are quite slow, but not that slow we need to optimize per word, the maximum image size is 800x384, no need to optimize anything. The slowness you might see comes purely from the downloading speed of that image.

Not to mention that kind of optimizations would just make more problems; for example i wouldnt be able to break the text if it makes the image too wide. and how about the memory use?? each word would need 18 different images to be loaded in worst case scenario.

I cant make PHP to preload the images into memory, its enough fast already, i dont think there is performance problems... i will check how many milliseconds it takes now to render it with full size image and all possible colors :D

ps. making the background feature now.
User avatar
Cuban-Pete
Immortal
Posts: 909
Joined: 29 Jan 2010, 15:03
GH nick: Cuban-Pete

Re: GTA2 Font Topic - TXT2GTA2 (Version 3 Released!)

Post by Cuban-Pete »

Okay, so optimization in php is not noticeable, but it is in the imagesize. Did the "palette-trick" work in lower imagesize? Have you also heard about pngcrush?
"Mmmm, your eyes are so beautiful."
User avatar
T.M.
Immortal
Posts: 960
Joined: 29 Jan 2010, 15:00
Location: F21B3EED

Re: GTA2 Font Topic - TXT2GTA2 (Version 3 Released!)

Post by T.M. »

Its not just PHP, but in general, its very impractical in any application to pre-generate billion different word combinations (we need a lot, or else we wouldnt see any performance increase since checking only few words would actually make it slower than without the optimization). not to mention, the memory use would be epic, or you would need to load new images all the time, which makes super slow performance.

i havent tried palette trick yet, what do you mean by imagesize...? i havent heard about pngcrush, does it compress PNG better? :O
Post Reply