We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36760
    • 136 Posts
    I'm working on a website that uses a image slider which requires image widths and heights to be set to function properly. Normally this isn't a problem, except on this website the images will be different sizes (particularly different widths). I would like to avoid needing to manually enter widths for every image.

    I came across a method for Modx Evolution and PhX for pulling widths and heights (http://modxrules.com/articles/how-to-output-the-height-and-width-of-an-image-tv), I just haven't had any luck adapting it to Modx Revolution.

    Here is what one of my output strings looks like, which is part of an MIGX Tpl:

    [[+image:notempty=`<a class="thickbox" href="[[+url]]?height=575&width=480&inlineId=hiddenModalContent&modal=true"><img src="[[+image]]" width="[[imageWidth]]" height="[[imageHeight]]" alt="" /></a>`]]


    The snippet calls in the width and height position go the respective snippets similar to the Evo example I linked.

    I would like them to work with the Default output selected, but I would be fine using the Image output if it's needed.

    Thanks for any help!
      • 4172
      • 5,888 Posts
      this should work:
      create both snippets, name them imageWidth and imageHeight

      and use it in your chunk like that:

      [[+image:notempty=`<a class="thickbox" href="[[+url]]?height=575&width=480&inlineId=hiddenModalContent&modal=true"><img src="[[+image]]" width="[[+image:imageWidth]]" height="[[+image:imageHeight]]" alt="" /></a>`]]
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 36760
        • 136 Posts
        Thanks for your help. Unfortunately, using that method just puts the image URL again.

        My Snippets look the same as the examples on the website I linked. I'm assuming they need to be updated for Revolution? I did some searching and couldn't find any information for getimagesize in Revolution, though I'm also not sure what the equivalent would be.

        imageHeight
        <?php
        list($width, $height, $type, $attr) = getimagesize($output);
        return $height;


        imageWidth
        <?php
        list($width, $height,$type,$attr) = getimagesize($output);
        return $width;

          • 4172
          • 5,888 Posts
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 36760
            • 136 Posts
            I think I'm getting somewhere.

            I tried just changing $output to $input, but that gives me a Fatal Error for exceeding the maximum execution time of 30 seconds.

            Then, I tried just putting in the path of an image instead, but that puts out the image URL again (but no errors).

            Sorry if I'm making this more difficult than it needs to be, was I missing something on the Modx documentation you linked me to?