We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25551 ☆ A M B ☆
    • 1,231 Posts
    Hey, I am using a script that creates graphs and charts using PHP which then generates an image. I can get it working as a stand alone script but I can’t style the page at all.

    I get lots of foreign characters... �PNG  ��� IHDR�����,�� for example

    I can create a php file with the script and it works but creating a snippet with the following does not.

    include("assets/snippets/Graph/graph.php");


    I have set the template to blank so there is no HTML characters but that’s not helped. If I go direct to the php file it works.

    Any idea how I can include the generated image in to a document and one that I can actually style? I have read and read but nothing is helping.
      Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
      AugmentBLU - MODX Partner

      BLUcart - MODX Revolution E-Commerce & Shopping Cart
      • 9207 ☆ A M B ☆
      • 2,475 Posts
      Two things:

      1) You need to watch your paths! You’re including a file of "assets/snippets/Graph/graph.php" -- but that targets a different file depending on where the script is executed. I’d recommend using the ’base_path’ variable:

      include_once($modx->config['base_path'].'assets/snippets/Graph/graph.php');


      This works so long as you have your base path set correctly in the manager Config.

      2) What do you mean by "style"? Do you mean how do you alter the text used in your chart image? That’s a good question. It looks like your web server may be missing some fonts -- that may explain the weird characters that you’re seeing. Are you sure you have the GD and FreeType libraries installed?

      What you might want to do in your page is something like this:
      <img src="/assets/snippets/Graph/dynamic_image_generator.php?param=value" />


      And then in the dynamic_image_generator.php page, print out your image. This approach will ensure that the browser interprets the script output as an image and not as text. It’s all about sending the correct headers.
        • 25551 ☆ A M B ☆
        • 1,231 Posts
        Thanks for the reply, I actually managed to get it sorted out... it was the second option. I had managed to figure that out earlier but took me a while!

        I just didn’t get how to include the generated image in a document that had html code... but got there in the end, thanks.
          Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
          AugmentBLU - MODX Partner

          BLUcart - MODX Revolution E-Commerce & Shopping Cart