wrong Encodng or fonts

The problem is like that.
I have a simple forum phpBB here: http://musicogenic.net/
if you view the source you'll see that the encoding is charset=iso-8859-7

Now lets get to the problem.
I use a little php script that i found somewhere ( i dont remeber), and i use it a signature.
It takes data from the phpbb forum and shows them in an image.

the file is this : http://musicogenic.net/whatever.php
The problem is that when the Last Topic: is in Greek characters, its not shown right, even if the encoding is iso-8859-7 as it should be.

The code of the file this :

<?php

define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);

// Get basic (usernames + totals) online
// situation
//
$user_forum_sql = ( !empty($forum_id) ) ? "AND s.session_page = " .
intval($forum_id) : '';
$sql = "SELECT u.username, u.user_id, s.session_logged_in, s.session_ip
    FROM ".USERS_TABLE." u, ".SESSIONS_TABLE." s
    WHERE u.user_id = s.session_user_id
        AND s.session_time >= ".( time() - 300 ) . "
        $user_forum_sql
    ORDER BY u.username ASC, s.session_ip ASC";
if( !($result = $db->sql_query($sql)) )
{
    message_die(GENERAL_ERROR, 'Could not obtain user/online information',
'', __LINE__, __FILE__, $sql);
}

$logged_online = 0;
$prev_user_id = 0;

while( $row = $db->sql_fetchrow($result) )
{
    // User is logged in and therefor not a guest
    if ( $row['session_logged_in'] )
    {
        // Skip multiple sessions for one user
        if ( $row['user_id'] != $prev_user_id )
        {
                $logged_online++;
        }

        $prev_user_id = $row['user_id'];
    }
}

$sql = 'SELECT max(topic_id)
FROM ' . TOPICS_TABLE;

if ( !($result = $db->sql_query($sql)) )
{
    message_die(GENERAL_ERROR, 'Couldn\'t retrieve max of Topic_id data',
'', __LINE__, __FILE__, $sql);
}

while ( $row = $db->sql_fetchrow($result))
{
    $max_topic_id = $row['max(topic_id)'];
}
$sql = 'SELECT topic_title
FROM ' . TOPICS_TABLE . '
WHERE topic_id = ' . $max_topic_id;

if ( !($result = $db->sql_query($sql)) )
{
    message_die(GENERAL_ERROR, 'Couldn\'t retrieve Topic_id data', '',
__LINE__, __FILE__, $sql);
}

while ( $row = $db->sql_fetchrow($result))
{
    $latest_topic = $row['topic_title'];
}

$image = "mypage.png";
$im = imagecreatefrompng($image);
$tc  = ImageColorAllocate ($im, 200, 150, 0);
$red  = ImageColorAllocate ($im, 255, 255, 255);
$blue  = ImageColorAllocate ($im, 255, 255, 255);
$green  = ImageColorAllocate ($im, 255, 255, 255);
$sitename = $board_config['sitename'];

$total_users = get_db_stat('usercount');
$total_posts = get_db_stat('postcount');
$total_topics = get_db_stat('topiccount');
$j = strlen($total_users);
$leerzeichen = $j*6+180;
$newest_userdata = get_db_stat('newestuser');
$newest_user = $newest_userdata['username'];
ImageString($im, 3, 98, 7, "Statistics Of : $sitename", $tc);
ImageString($im, 2, 98, 25, "Users : $total_users -", $tc);
ImageString($im, 2, $leerzeichen, 25, "Online: $logged_online", $red);
ImageString($im, 2, 98, 35, "Latest Topic :", $tc);
ImageString($im, 2, $leerzeichen, 35, "$latest_topic", $blue);
ImageString($im, 2, 98, 45, "Posts: $total_posts in $total_topics
Topics", $tc);
ImageString($im, 2, 98, 55, "Newest registered user :", $tc);
ImageString($im, 2, 260, 55, "$newest_user", $green);
header("Content-Type: image/png; charset:iso-8859-7");
Imagepng($im,'',100);
ImageDestroy ($im);

?>

Any ideas?
LVL 2
MaRiOsGRAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bernard S.CTOCommented:
Hi,
The only thing sure, is that something is wrong. Isolating which part will be the most difficult, 'cause the solution should be simple.
1 - Check the char code selected in YOUR browser (automatic? greek? 9951-7?) when you have the problem AND when you have not. In some occasions "automatic" can be fooled. At the same time, experiment with manually changing the char code selected. Is there a "magical situation", where all would be fine?
2 - experiment with additional characters before and after your signature, eg, write xxx before and yyy after. Do these extra display correctly? all?

3 - Your line [header("Content-Type: image/png; charset:iso-8859-7")] puzzles me (but I'm not an expert at this)for 2 reasons
a - I would guess that since you have already sent characters to the client, this line is at best uneffective (but I'm very probably wrong)
b - If you say that content is an image, why would character encoding be used?

4 - I would think that the character encoding has to be done not at the header level (since graphics are sent, not text) but at the image preparation level (imagestring). Using imageloadfont might become mandatory...
MaRiOsGRAuthor Commented:
Hello Fibo,

1.nothing works, its not a browser matter as it seems.
2.I dont have to do that cause, if the Last Topic in a new thread inside the forum is writte in a)english b)latin characters
in the signature it works fine, so the problem is only when the Topic Subject in the forum is written in Greek characters.
3.To be honest the original script was like that: Content-Type: image/png and I added the charset:iso-8859-7 but it has no effect anyway...its useless and you are right about that!!!! :)
4.how can I do that ? :D
siliconbritCommented:

Hi Mario,

The problem is nothing to do with the headers you are putting out to the browser.

You are creating an image, and embedding the text within that image, once the image is created, there is no text available that is affected by the charset you are using.

I'm no expert with the GD library, but I believe you need to load the required font when you build your GD object.

Documentation on the GD library is at: http://www.boutell.com/gd/

I once read somewhere that you need to load the Unicode font to do this, but I've never needed to create a GD image with embedded international text, so my advice would be to google for information on "GD unicode fonts" or similar.




Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

Gee_OrgeCommented:
Well it's seems that  you must use the imagettftext() function to pass the string, into the png image, using a TrueType font, instead of the imagestring(), notice that the string must be in utf-8 encoding, try to use the ConvertCharset Class, which can be found at the http://www.phpclasses.org

cheers m8 ;)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MaRiOsGRAuthor Commented:
Gee_Orge that worked.
thank you.
Bernard S.CTOCommented:
Mario,
Would you do us the favor to post the revised script, so that we can make a copy of the result?
I did not think to these kinds of use before, you open me new fields!
Thx.
Bernard
MaRiOsGRAuthor Commented:
Yes now the code is this :

<?php

define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
// Get basic (usernames + totals) online
// situation
//
$user_forum_sql = ( !empty($forum_id) ) ? "AND s.session_page = " .
intval($forum_id) : '';
$sql = "SELECT u.username, u.user_id, s.session_logged_in, s.session_ip
    FROM ".USERS_TABLE." u, ".SESSIONS_TABLE." s
    WHERE u.user_id = s.session_user_id
        AND s.session_time >= ".( time() - 300 ) . "
        $user_forum_sql
    ORDER BY u.username ASC, s.session_ip ASC";
if( !($result = $db->sql_query($sql)) )
{
    message_die(GENERAL_ERROR, 'Could not obtain user/online information',
'', __LINE__, __FILE__, $sql);
}

$logged_online = 0;
$prev_user_id = 0;

while( $row = $db->sql_fetchrow($result) )
{
    // User is logged in and therefor not a guest
    if ( $row['session_logged_in'] )
    {
        // Skip multiple sessions for one user
        if ( $row['user_id'] != $prev_user_id )
        {
                $logged_online++;
        }

        $prev_user_id = $row['user_id'];
    }
}

$sql = 'SELECT max(topic_id)
FROM ' . TOPICS_TABLE;

if ( !($result = $db->sql_query($sql)) )
{
    message_die(GENERAL_ERROR, 'Couldn\'t retrieve max of Topic_id data',
'', __LINE__, __FILE__, $sql);
}

while ( $row = $db->sql_fetchrow($result))
{
    $max_topic_id = $row['max(topic_id)'];
}
$sql = 'SELECT topic_title
FROM ' . TOPICS_TABLE . '
WHERE topic_id = ' . $max_topic_id;

if ( !($result = $db->sql_query($sql)) )
{
    message_die(GENERAL_ERROR, 'Couldn\'t retrieve Topic_id data', '',
__LINE__, __FILE__, $sql);
}
while ( $row = $db->sql_fetchrow($result))
{
    $latest_topic = $row['topic_title'];
}

//NEW CODE
include ("xtras/ConvertCharset.class.php");
$conv = new ConvertCharset();
$latest_topic = $conv->Convert($latest_topic, "iso-8859-7", "utf-8");
//ENDS HERE

$image = "mypage.png";
$im = imagecreatefrompng($image);
$tc  = ImageColorAllocate ($im, 200, 150, 0);
$red  = ImageColorAllocate ($im, 255, 255, 255);
$blue  = ImageColorAllocate ($im, 255, 255, 255);
$green  = ImageColorAllocate ($im, 255, 255, 255);
$sitename = $board_config['sitename'];

$total_users = get_db_stat('usercount');
$total_posts = get_db_stat('postcount');
$total_topics = get_db_stat('topiccount');
$j = strlen($total_users);
$leerzeichen = $j*6+180;
$newest_userdata = get_db_stat('newestuser');
$newest_user = $newest_userdata['username'];
ImageString($im, 3, 98, 7, "Statistics Of : $sitename", $tc);
ImageString($im, 2, 98, 25, "Users : $total_users -", $tc);
ImageString($im, 2, $leerzeichen, 25, "Online: $logged_online", $red);
ImageString($im, 2, 98, 35, "Latest Topic :", $tc);
// NEW LINE
imagettftext($im, 8, 0, $leerzeichen, 45, $blue, "./courbd.ttf", $latest_topic);
// ENDS HERE
ImageString($im, 2, 98, 45, "Posts: $total_posts in $total_topics Topics", $tc);
ImageString($im, 2, 98, 55, "Newest registered user :", $tc);
ImageString($im, 2, 260, 55, "$newest_user", $green);
header("Content-Type: image/png;");
Imagepng($im,'',100);
ImageDestroy ($im);

?>
Bernard S.CTOCommented:
thx
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Fonts Typography

From novice to tech pro — start learning today.