We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26503
    • 620 Posts
    Original image widths & heights for gallery...

    Does anyone know if it is possible to pass the original image widths and heights to the gallery item/row/thumb tpl? I am using awslider which has the ability to dynamically alter the height of the display div IF it has the image dimensions ~ which I could not find out how to do with gallery....

    -thanks
    -sean [ed. note: sean69 last edited this post 14 years, 8 months ago.]
      *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

      Sean Kimball CLP, CLS.
      Technical Director / Sr. Developer | BigBlock Studios
      ._______________________________________________.
      Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
      27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
      phone/fax: 905-426-5525
      • 18373 ☆ A M B ☆
      • 3,141 Posts
      So you want the actual width/height of the original image... or do you want the original image not being resized?
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
        • 26503
        • 620 Posts
        I have situations where both dimensions will be useful. The first being the actual image dimensions after being pumped through connector.php & the actual dimensions of the image that resides in /assets/components/gallery/files/_galleryid_/_image_name_

        I was working on a snippet to get the org image sizes...

        [[!getImageSize? &src=`[[!+gallery.id]]/[[!+galitem.filename]]` ]]
        
        
        # getImageSize snippet
        $imgsrc = MODX_BASE_PATH . 'assets/components/gallery/files/' . $src;
        //echo $imgsrc;
        $imginfo = getimagesize(&imgsrc);
        return $imginfo[3];
        
        
        #the image tag
        <img 
             class="[[+galitem.imgCls]]" 
             src="/assets/components/gallery/files/[[!+gallery.id]]/[[!+galitem.filename]]" 
             alt="[[+galitem.name]]" 
             [[!getImageSize? &src=`[[!+gallery.id]]/[[!+galitem.filename]]` ]]
        />
        
        


        but seem to be having issues with that too... It was working and returning the height & width, but now it seems broken again.....


        UPDATE:

        hmmm, it seems fine with this:
        [[!getImageSize? &gallery=`2` &image=`25.jpg` ]]


        but not this:
        [[!getImageSize? &gallery=`[[+gallery.id]]` &image=`[[+galitem.filename]]` ]]
        


        (I split the $src up into $gallery & $image)

        I get a modx error warning:

        [2012-02-12 15:53:56] (ERROR @ /var/www/vhosts/gaycompanylimited.com/httpdocs/core/cache/includes/elements/modsnippet/24.include.cache.php : 18) PHP warning: getimagesize(/var/www/vhosts/gaycompanylimited.com/httpdocs/assets/components/gallery/files/[[+gallery.id]]/[[+galitem.filename]]) [<a href='function.getimagesize'>function.getimagesize</a>]: failed to open stream: No such file or directory
        


        but the file is clearly there ,,,?!?! [ed. note: sean69 last edited this post 14 years, 8 months ago.]
          *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

          Sean Kimball CLP, CLS.
          Technical Director / Sr. Developer | BigBlock Studios
          ._______________________________________________.
          Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
          27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
          phone/fax: 905-426-5525
          • 18373 ☆ A M B ☆
          • 3,141 Posts
          Line 7, &imgsrc should be $imgsrc.

          There's also the image_absolute placeholder which contains the actual link to the original image, you may want to use that too.

            Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

            Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
            • 26503
            • 620 Posts
            Hi Mark;

            "Line 7, &imgsrc should be $imgsrc." ~ yes I did catch that, no it still does not work...

            Also, [[+image_absolute]] seems to work fine for the gallery tag, but not as part of the galleryitem tag.

            getting frustrated... grrr.

            -sean [ed. note: sean69 last edited this post 14 years, 8 months ago.]
              *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

              Sean Kimball CLP, CLS.
              Technical Director / Sr. Developer | BigBlock Studios
              ._______________________________________________.
              Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
              27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
              phone/fax: 905-426-5525
              • 26503
              • 620 Posts
              OK - got a working solution.... I added this to the GalleryItem snippet:

              // start image dimension placeholders
              $itemArray['image_absolute'] = $modx->getOption('gallery.files_url').$item->get('filename');
              $dimensions = getimagesize(MODX_BASE_PATH . $itemArray['image_absolute']);
              $itemArray['dimensionx'] = $dimensions[0];
              $itemArray['dimensiony'] = $dimensions[1];
              $itemArray['dimensionxy'] = $dimensions[3];
              // end image dimension placeholders
              
              /* if outputting to placeholders, use this, otherwise, use tpl */
              if ($toPlaceholders) {
                  $modx->toPlaceholders($itemArray,$toPlaceholdersPrefix);
                  return '';
              }
              


              now we can use the output placeholdersl dimensionx, dimensiony & dimensionxy in our galleryItem chunk:

              [[!GalleryItem? &imageWidth=`550` ]]
              
              <div class="image">
                <a href="[[+galitem.image]]">
              <img class="[[+galitem.imgCls]]" src="[[+galitem.image]]" alt="[[+name]]" [[!+galitem.dimensionxy]] /></a>
                <br />Albums: [[+galitem.albums]]
                <br />Tags: [[+galitem.tags]]
              <br /> FileName: [[+galitem.filename]]
              <br /> ID: [[+galitem.id]]
              <br /> Album: [[+galitem.albums]]   [[+gallery.id]]
              <br /> Dimension x: [[!+galitem.dimensionx]]
              <br /> Dimension y: [[!+galitem.dimensiony]]
              <br /> Dimension xy: [[!+galitem.dimensionxy]]
              </div>
              


              -sean
                *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

                Sean Kimball CLP, CLS.
                Technical Director / Sr. Developer | BigBlock Studios
                ._______________________________________________.
                Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
                27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
                phone/fax: 905-426-5525
                • 40118
                • 10 Posts
                If you want to save the image dimensions without worrying about initial uncached getImageSize snippet call performance. Goto: galitem.class.php in core/components/gallery

                In the save() function, just before
                 $saved= parent :: save($cacheFlag);
                


                insert:
                $desc = $this->get('description');
                		if ( empty( $desc ) ) {
                			$this->getSize();
                			$this->set('description', $this->get('image_width').'x'.$this->get('image_height') );
                		}
                



                This will automatically create a description like "130x110" (width x height) just before saving, provided the description field is left empty. So, you don't need to worry about getimagesize() performance, even though snippet calls can be cached (but it'll still require a first run to cache it..). A hackish way to go about it..i know. Just got to remember to leave description field empty though upon saving.

                By right, you should create a new database column, a new placeholder, a new PDO field, etc.