We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10313
    • 375 Posts
    Hello,

    I want to build a menu with graphical buttons. The buttons should be placed into the background of the a-tag so that I can alter the background-position on hover and active. To do this, I need to know how wide the image is, so that I can tell the a-tag to be that wide. I would do this with a small snippet call from within the wayfinder template chunk.

    Is there already such a snippet oder should I code one myself?

    Thanks for hints
    Martin
      • 29774
      • 386 Posts
      Do you really need to know the width? Why not stack the button states vertically in the image, assuming the button height is fixed? Or use percentages for background positioning.
        Snippets: GoogleMap | FileDetails | Related Plugin: SSL
        • 24495
        • 407 Posts
          • 29774
          • 386 Posts
          Heh, that’s actually my snippet. It won’t tell you the width/height of an image though, sorry.
            Snippets: GoogleMap | FileDetails | Related Plugin: SSL
            • 24495
            • 407 Posts
            grin it’s friday p.m. cool

            Let me look around my projects ... there must be a custom snippet. Till later ...
              • 24495
              • 407 Posts
              It’s an idea for your individual improvement:
              <?php
              $id= (isset($id))? $id : $modx->documentIdentifier; //if needed for further processing
              
              $imgsrc = .....; //path_to_the_image wherever you'll get them
              
              $basePath = $modx->config['base_path'];
              $orig_size = GetImageSize($basePath . $imgsrc);
              $imgwidth = $orig_size[0];
              $imgheight = $orig_size[1];
              
              return '<img src="'.$imgsrc.'" width="'.$imgwidth.'" height="'.$imgheight.'" />';
              ?>
                • 10313
                • 375 Posts
                Yeah, I knew it wouldnt be too hard to do, just didn’t want to code a snippet that already exists. Your code is very fine for me as a base.

                Thank you
                Martin
                  • 10449
                  • 956 Posts
                  You can use index 3 smiley

                  $orig_size = getimagesize($basePath . $imgsrc);
                  $imgWH = $orig_size[3];
                  return "<img src=\"$imgsrc\" $imgWH />";
                  


                  from the manual:
                  Index 3 is a text string with the correct height="yyy" width="xxx" string that can be used directly in an IMG tag.