We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34178
    • 212 Posts
    We were going to create graphics by a snippet by this example-code but it doesn´t work. Does anybody have an idea what we did wrong?

    <?php
     $image = imagecreate(1200,700);
     $color_body = imagecolorallocate($image,200,200,200);
     imagefill($image, 0, 0, $color_body);
     header("Content-Type: image/jpeg");
     imagejpeg($image,"",100);
     imagedestroy($image);
    ?>
    


    We called the snippet without success by
    [[!graphic]]
    and also by
    <img src="[[!graphic]]" />


    The only way it works is to put the code in an extra file beside modx like graphic.php and call this file in modx by <img src="graphic.php" />
    • Hello,

      I'm the last person to ask for php advise, but my gut is telling me setting the header is your problem. Snippet's allow php code, but they don't function like individual php files.

      I would suggest looking at phpthumb/phpthumbof as an alternative. They should allow you to do what you want.
        Patrick | Server Wrangler
        About Me: Website | TweetsMODX Hosting
        • 34178
        • 212 Posts
        Thanks for your hint. Probably you are right.

        We were going to produce dynamic diagrams for showing tracking-results/page-countings. Do you think phpthumb is suitable for this aim, too?
          • 3749
          • 24,544 Posts
          I'm pretty sure that what you have is correct. It has to be in an external file because when parsing the <img> tag, the browser treats the src as a URL.

          You can control the image-producing php code by sending _$GET or _$POST variables or by using $_SESSION variables, but I don't think there's any way to do it without an external file.

          You could look at the code of the Captcha plugin for ideas. It creates images on the fly for display as the Captcha challenge and it will (optionally) render a sting you send it as part of the image.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
          • Well, phpthumb is geared more towards thumbnail creation, but it may also work for image creation after all it's just a frontend of sorts for GD/ImageMagick.

            I don't know about your specific usage, but look over the phpthumb site and it should give you an idea.
              Patrick | Server Wrangler
              About Me: Website | TweetsMODX Hosting