We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34120
    • 236 Posts
    I'm using Gallery to display images for an album on a page. I'm not using thumbnails just the main images. They are being resized to a fixed height of 600px but they all have variable width. I need to be able to pass the width value into the img width attribute in the thumbTpl.

    Gallery call:
    [[Gallery?
        &imageHeight=`600`
        &imageWidth=`0`
        &thumbTpl=`galleryImages`
        &toPlaceholder=`gallery`
    ]]
    thumbTpl:
    <img src="[[+image]]" width="[[+need-width-here]]" height="600"/>

    I have tried using a getImageSize snippet, this returns nothing, I've a feeling this is something to do with the image url generated by phpThumb. If I change the src to [ [+image_absolute]] then it works. However this is the incorrect width as the absolute image hasn't been run through phpThumb.

    thumbTpl:
    <img src="[[+image]]" width="[[getImageSize? &src=`[[+image]]`]]" height="600"/>

    getImageSIze snippet
    <?php
    $imagesize = getimagesize("/some_path/" . $src);
    $width = $imagesize[0]; // width
    return $imagesize[0];

    I've looked at running the image through phpThumbOf but can't get this to work either as I get an incorrect file path. Theres a few threads around about this:
    https://forums.modx.com/thread/?thread=31377&page=1
    https://forums.modx.com/thread/?thread=50628&page=1

    Any ideas or workarounds?
    Thanks!
      • 34120
      • 236 Posts
      Also on a related note Gallery uses phpthumb to fetch the [ [+image]] I presume it checks to see if the image exists first or is it running and rescaling everytime the page is refreshed?
        • 37242 ☆ A M B ☆
        • 339 Posts
        It is caching the resized images (as far as in know).

        [ed. note: gallenkamp last edited this post 14 years, 3 months ago.]
          • 34120
          • 236 Posts
          Thanks gallenkamp,

          Does anyone have any ideas on the width issue?
            • 34120
            • 236 Posts
            bump

            Anyone?
              • 34120
              • 236 Posts
              Making some progress, I've got my getImageSize snippet working. I had to do a bit of wrangling to get the correct url for getimagesize. It doesn't like the url string presented by phpthumb hence the urldecode. I also had to hardcode the site url for some reason.
              <?php
              $imagesize = getimagesize('http ://www.mydomain.com/' . urldecode(str_replace('&', "&" , $src)));
              $width = $imagesize[0]; // width
              return $width;

              thumbTpl:
              <img src="[[+image]]" width="[[getImageSize? &src=`[[+image]]`]]" height="600"/>


              I'm loading the images into a carousel so I'm calling all the main images from a gallery onto one page. The problem now is I'm taking a big performance hit as this snippet is running for each image. There is a fairly big lag between clicking on a gallery link and being taken to the gallery page.

              The only workaround I can think of so far is to write the image width to the DB and pull it from there. Any pointers on how to do this? I'm not using tags so I thought about writing the widths to tags?? [ed. note: bobwal last edited this post 14 years, 3 months ago.]
                • 40452
                • 10 Posts
                I tried your snippet...

                Is the same snippet working for you with latest Gallery Extra and latest Modx Revo?

                Thanks
                  • 34120
                  • 236 Posts
                  Hi,
                  I'm not sure what the latest version of gallery is and there seems to be a problem with the Extras page at the moment but I have this running on:

                  MODX Revolution 2.2.4-pl
                  Gallery 1.5.1

                  Are you having problems?
                    • 40452
                    • 10 Posts
                    Thanks for the reply bobwal . I got it working with a couple of additional features

                    https://forums.modx.com/thread/78506/best-way-to-pick-up-the-width-and-height-of-the-uploaded-image#dis-post-432721 [ed. note: rohan.r last edited this post 14 years, 2 months ago.]