Ad Widget

Collapse

Non-Latin characters in graphs?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • technow0rker
    Junior Member
    • Apr 2006
    • 26

    #1

    Non-Latin characters in graphs?

    Hello.

    Can I use cyrillic characters when drawing text in Zabbix graphs? Maybe I'm doing something wrong, because currently cyrillic strings are not displayed (displayed as unreadable characters). I suppose this is more PHP/GD issue than a Zabbix one, but maybe someone knows how to deal with this? Or maybe I should use different (i.e. UTF-8) encoding? (I use windows-1251 for now).

    Some useful links:

    GD KOI8 fonts



    Terminus font collection and some useful tools
    Информация за най-важните събития в сферата на финансите, икономиката, бизнеса, съботия, кредити и още много!


    Tool: trbdf - convert BDF-font from one encoding to other
    Last edited by technow0rker; 19-04-2006, 11:14.
  • technow0rker
    Junior Member
    • Apr 2006
    • 26

    #2
    After digging google I've found answer for the question above. It's defitively a GD issue. One should find appropriate fonts for particular encoding and recompile GD library, because Zabbix uses GD built-in fonts and they contain only latin characters (AFAIK). Will try to do so soon

    Comment

    • Darken
      Junior Member
      • Dec 2006
      • 2

      #3
      It can be done by editing php frontend code.

      For ZABBIX v.1.0 I successfully draw a cyrillic characters on graphs and maps by using an UTF-8 fonts and replace "ImageString" function with "ImageTTFText" in php-frontend code. And You also should use an appropriate encoding in database. I am currently useing MySQL, database was setup only once a log time ago with koi8-u charset.
      For ZABBIX 1.0 it was ease. In version 1.1 the frontend code become more complex and it was mush harder for me to find out a plase where to make replacement. Currently I just made quick upgrade to 1.1.4 and unfortunately forgot to backup my changes, so now I will try to find the way to replace a default font that use "ImageString", if not - I'll adit the php frontend code once more.
      Here an example of my "code replacement" form version 1.0:
      {ZABBIX_HOME}/html/chart4.php:110:
      //$x=imagesx($im)/2-ImageFontWidth(4)*strlen($str)/2;
      //ImageString($im, 4,$x,1, $str , $darkred);
      $font="/usr/java/j2re1.4.2_04/lib/fonts/LucidaSansRegular.ttf";
      $str=iconv('KOI8-U','UTF-8',$str);
      $pos=ImageTTFBBox(10,0,$font,$str);
      $x=(imagesx($im)-($pos[2]-$pos[0]))/2;
      ImageTTFText($im,10,0,$x,13,$darkred,$font,$str);
      {ZABBIX_HOME}/html/chart5.php:102:
      //$x=imagesx($im)/2-ImageFontWidth(4)*strlen($str)/2;
      //ImageString($im, 4,$x,1, $str , $darkred);
      $font="/usr/java/j2re1.4.2_04/lib/fonts/LucidaSansRegular.ttf";
      $str=iconv('KOI8-U','UTF-8',$str);
      $pos=ImageTTFBBox(10,0,$font,$str);
      $x=(imagesx($im)-($pos[2]-$pos[0]))/2;
      ImageTTFText($im,10,0,$x,13,$darkred,$font,$str);
      ...
      and so on.

      Comment

      • Darken
        Junior Member
        • Dec 2006
        • 2

        #4
        It can be done by rebuilding php.

        Since I did not longing for editing php-frontend code, I find out how to replace the default font that used by "ImageString" function. In my case I had to rebuild php package.

        So I found suitable font (koi8-c for me) here:
        Latest news coverage, email, free stock quotes, live scores and video are just the beginning. Discover more every day at Yahoo!


        Generate headers and souce files for GD library:
        $ cat koi9x15b.bdf | ./bdftogd FontGiant gdfontg
        $ cat koi8x16.bdf | ./bdftogd FontLarge gdfontl
        $ cat koi7x14b.bdf | ./bdftogd FontMediumBold gdfontmb
        $ cat koi6x13.bdf | ./bdftogd FontSmall gdfonts
        $ cat koi5x8.bdf | ./bdftogd FontTiny gdfontt

        Edit them to correspond the function export syntax found in original source files, replace, rebuild and reinstall php.
        Attached Files

        Comment

        • evgeny elkin
          Member
          • Jul 2007
          • 52

          #5
          Is anybody solve this problem with GD in latest zabbix versions? I use KOI8-R encoding, and labels for hosts is not correctly displaying on maps, is there any more elegance method, than recompiling GD? Thanks!

          Comment

          • evgeny elkin
            Member
            • Jul 2007
            • 52

            #6
            Solved.

            Solve this problem by the easyest way for me - editing frontend code:

            In map.php

            # add a font for koi8-r
            $font="./fonts/cokoi8n.ttf";
            #

            # and change a code

            {
            # ImageFilledRectangle($im,
            # $x_label-2, $y_label,
            # $x_label+ImageFontWidth(2)*strlen($label_line), $y_label+ImageFontHeight(2),
            # $white);
            ImageFilledRectangle($im, 0, 0, 0, 0, $white);
            # ImageString($im, 2, $x_label, $y_label, $label_line,$label_color);

            ImageTTFText($im, 8, 0, $x_label, $y_label+,ImageFontHeight(2) $label_color, $font, $label_line);
            }

            if($info_line!="")
            {
            # ImageFilledRectangle($im,
            # $x_info-2, $y_info,
            # $x_info+ImageFontWidth(2)*strlen($info_line), $y_info+ImageFontHeight(2),
            # $white);
            ImageFilledRectangle($im, 0, 0, 0, 0, $white);
            # ImageString($im, 2, $x_info, $y_info, $info_line,$color);

            ImageTTFText($im, 8, 0, $x_info, $y_info+ImageFontHeight(2), $color, $font, $info_line);
            }
            Attached Files
            Last edited by evgeny elkin; 02-08-2008, 08:21.

            Comment

            • tekknokrat
              Senior Member
              • Sep 2008
              • 140

              #7
              ttf fonts in maps/graphs

              i also want to use more elegant ttf font for graphs and maps.
              I tried the way suggested above but this gives me no output at all.
              I tried with a simple ttf test for checking if my server is setup correctly and this works.

              why does this output of "test" not works?
              Code:
               $font           = './VeranMono.ttf';
              ...
               $darkred        = ImageColorAllocate($im,150,0,0);
              ...
                     ImageFilledRectangle($im,0,0,$width,$height,$white);
              
                      if(($db_image = get_image_by_imageid($backgroundid)))
                      {
                              $back = ImageCreateFromString($db_image["image"]);
                              ImageCopy($im,$back,0,0,0,0,imagesx($back),imagesy($back));
                      }
                      else
                      {
                              $x=imagesx($im)/2-ImageFontWidth(4)*strlen($name)/2;
                              # ImageString($im, 4, $x, 1, $name , $darkred);
                              ImageTTFText($im, 12, 0, 20, 80, $darkred, $font, "test");
              
                      }

              Comment

              Working...