We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37523
    • 141 Posts
    When I use imagegif to display a image on the page I get a stream of code with in the browser such as:
    GIF87a�b�lz|�����䌞����|�����������t�������윦���܄

    Where am I going wrong?

    The code within my snippet is:
    $cog1 = imagecreatefromgif('xresource/images/icons/tocLay1_contPerfImprov.gif');
    $imageContainer = imagecreatetruecolor(180, 98);
    imagecopy($imageContainer, $cog1, 0, 0, 0, 0, 180, 98);
    header ('Content-Type: image/gif');
    imagegif($imageContainer);
    imagedestroy($cog1);
    imagedestroy($imageContainer);
    return;

    If I run this code outside of MODX it executes well. Ideally I would like the above to work within a
    <img src="[[displayMygif]]">


    I have tried to call a external file containing the above within MODX as follows:
    require_once('xGraphic/showaGif.php');
    return;
    

    This gave me the similar stream of code as above.

    If MODX is incapable of allowing the above to work. How do I call this as a external script within MODX within a img tag

    I am using MODX 2.4.0. I am not sure what affect that would have on the above behaviour

    Many thanks in advance.

    This question has been answered by sottwell. See the first response.

    [ed. note: glynszasz last edited this post 8 years, 7 months ago.]
      Glyn Szasz
      Sydney, Australia

      Happy to help (when can) and happy to learn

      If you are a Sydney based MODX developer would love to hear from you. Please contact me.
    • According to the PHP docs,
      filename

      The path to save the file to. If not set or NULL, the raw image stream will be outputted directly.
      http://php.net/manual/en/function.imagegif.php
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
      • discuss.answer
        Actually this depends on how you are using this snippet. Is it the only thing on the page, or is it supposed to be an image displayed on a page of other content?

        I'd write it to a file, then output a normal img link to the file.

        Is the page itself the image which is generated with that snippet? Then change the resource's content type to be image/gif in its settings (you will need to create a new content type). [ed. note: sottwell last edited this post 8 years, 7 months ago.]
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 37523
          • 141 Posts
          Many thanks Susan. It seems by defining a path and outputting a file is the way to go.
            Glyn Szasz
            Sydney, Australia

            Happy to help (when can) and happy to learn

            If you are a Sydney based MODX developer would love to hear from you. Please contact me.