• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 758
  • Last Modified:

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?
0
MaRiOsGR
Asked:
MaRiOsGR
1 Solution
 
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...
0
 
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
0
 
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.




0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
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 ;)
0
 
MaRiOsGRAuthor Commented:
Gee_Orge that worked.
thank you.
0
 
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
0
 
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);

?>
0
 
Bernard S.CTOCommented:
thx
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now