We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31979
    • 26 Posts
    I am currently in the process of implementing phpThumb as a snippet. You can watch the very first results here: http://www.waso.com/thumb.html The snippet will be called "thumb" and the syntax will be:
    [[thumb? &image=`path to image` &alt=`optional, alt text` &h=`optional, height` &w=`optional, width`]]
    

    If there is a template variable [*image*], it should be possible to call the snippet like that:
    [[thumb? &image=`tvimage` &h=`100` &w=`100`]]
    

    Since this is my first MODx snippet, may I ask the following questions:
    How do I make the snippet accept template variables as parameters?
    I suppose this is not a built in functionality of MODx and has to be implemented in the snippet code?
    Is there any code I could reuse for that?
      www.waso.com
      • 25663 MODX Staff
      • 12,272 Posts
      Nothing built into MODx... if you want to use a TV, just put it in there:

      [[thumb? &image=`[*image*]` ... ]]

      Does phpThumb support caching?
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 11975
        • 2,542 Posts
        Hi,

        You could find some info here and sample code

        http://modxcms.com/forums/index.php?topic=3163.0
          Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
          • 31979
          • 26 Posts
          1.) Thank you for pointing me in the right direction, I was missing the obvious here! smiley

          2.) Yes phpThumb() does support caching.
            www.waso.com
            • 31979
            • 26 Posts
            It works now. I hope this is of some use.

            Examples, Instructions & Download: http://www.waso.com/thumb.html

            Snippet code. Copy & paste if you already have phpThumb installed:

            <?php
            // Name: thumb
            // Version: 0.1
            // Author: Thomas Wagensommerer
            // Date: 5.1.2007
            // Description: thumb is a simplified MODx frontend for phpThumb()
            
            // Installation:
            // phpThumb() by James Heinrich
            // is required to use thumb
            // download phpThumb at: http://phpthumb.sourceforge.net/
            // copy it into assets/snippets/phpThumb/
            // create a new snippet "thumb"
            // paste this text into it
            
            // Parameters:
            // image: path to image file
            // alt: alt tag for the image, optional
            // h: height of thumbnail, optional if w is given
            // w: width of thumbnail, optional if h is given
            
            // Example:
            // [[thumb? &image=`assets/images/picture.jpg` &w=`150` &h=`150`]]
            
            // Instructions:
            // if the image should retain its proportions only one parameter, h or w, is required
            // if both parameters h and w are given, the image is zoomed and cropped to fill that area
            
            $altstring = isset($alt)? ' alt="'.$alt.'"' : ' alt="image"';
            $heightstring = isset($w)? ' width="'.$w.'"' : '';
            $widthstring = isset($h)? ' height="'.$h.'"' : '';
            
            $wstring = isset($w)? '&w='.$w : '';
            $hstring = isset($h)? '&h='.$h : '';
            if (($w<>'') and ($h<>'')) $zcstring = '&zc=1';
            
            return '<img src="/assets/snippets/phpThumb/phpThumb.php?src=/'.$image.$wstring.$hstring.$zcstring.$altstring.$heightstring.$widthstring.'/>';
            ?>
              www.waso.com
              • 9549
              • 93 Posts
              Great work. Thanks waso.
                • 6726
                • 7,075 Posts
                Ok but there was a Thumb snippet already tongue

                Might want to change the name, otherwise we might end up talking about different snippets with the same name, might not be great for support undecided

                Maybe you two should compare and make the best of it, didn’t give a peak at code differences, but might be worht it...
                  .: COO - Commerce Guys - Community Driven Innovation :.


                  MODx est l&#39;outil id
                  • 2191
                  • 64 Posts
                  Great snippet...but a small problem. The altstring, heightstring, and width string need to be separated from the "src" markup. See my fixed code for details.

                  $altstring = isset($alt)? ' alt="'.$alt.'"' : ' alt="image"';
                  $heightstring = isset($w)? ' width="'.$w.'"' : '';
                  $widthstring = isset($h)? ' height="'.$h.'"' : '';
                  $class = isset($class)? ' class="'.$class.'"' : '';
                  
                  $wstring = isset($w)? '&w='.$w : '';
                  $hstring = isset($h)? '&h='.$h : '';
                  if (($w<>'') and ($h<>'')) $zcstring = '&zc=1';
                  
                  return '<img src="/assets/snippets/phpThumb/phpThumb.php?src=/'.$image.$wstring.$hstring.$zcstring.'"'.$altstring.$heightstring.$widthstring.$class.'/>';