?
Solved

wrong Encodng or fonts

Posted on 2006-03-22
8
Medium Priority
?
752 Views
Last Modified: 2013-12-03
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
Comment
Question by:MaRiOsGR
8 Comments
 
LVL 29

Expert Comment

by:fibo
ID: 16256447
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
 
LVL 2

Author Comment

by:MaRiOsGR
ID: 16256485
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
 
LVL 11

Expert Comment

by:siliconbrit
ID: 16257117

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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 4

Accepted Solution

by:
Gee_Orge earned 2000 total points
ID: 16261415
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
 
LVL 2

Author Comment

by:MaRiOsGR
ID: 16261660
Gee_Orge that worked.
thank you.
0
 
LVL 29

Expert Comment

by:fibo
ID: 16268879
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
 
LVL 2

Author Comment

by:MaRiOsGR
ID: 16270024
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
 
LVL 29

Expert Comment

by:fibo
ID: 16274484
thx
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month15 days, 9 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question