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

    I recently discovered MODx Revolution, and I love this CMS. Most problems I run in to, I solve with the help of old threads on this forum.

    So, what I want to do, is to use the snippet phpthumbof in my own snippet.
    The snippet phpthumbof works great when I use it in a template, and I want the output of this:
    [[*boxImage1:phpthumbof=`w=280&h=180&zc=1`]]
    ..to be used in my own snippet, that I use to generate xhtml.

    I’ve found the runSnippet function, but I don’t know if that’s what I want here, or how to use it.

    Grateful for help smiley

    /E
      • 31946
      • 116 Posts
      Hi Eminos

      I think to use the runSnippet method should work.
      Try out the following.

       
      $input = "pathtoimage/image.jpg";
      $width = 200;
      $height = 50;
      $options = "w=$width&height=$height&zc=1";   
      $thumbnail = $modx->runSnippet("phpthumbof",array('input' => $input, 'options' => $options));
      


      The variable $thumbnail should now containing the path to your thumbnail image.
      I didn’t test the code...

      Cheers
        • 14822
        • 61 Posts
        Hey Wanze tnx a lot, was exactly what I needed for my snippet. a simple galery with nivo slider

        <?php
        function getFileList($dir)
          {
            // array to hold return value
            $retval = array();
        
            // add trailing slash if missing
            if(substr($dir, -1) != "/") $dir .= "/";
        
            // open pointer to directory and read list of files
            $d = @dir($dir) or die("getFileList: Failed opening directory $dir for reading");
            while(false !== ($entry = $d->read())) {
              // skip hidden files
              if($entry[0] == ".") continue;
              if(is_dir("$dir$entry")) {
                $retval[] = array(
                  "name" => "$dir$entry/",
                  "type" => filetype("$dir$entry"),
                  "size" => 0,
                  "lastmod" => filemtime("$dir$entry")
                );
              } elseif(is_readable("$dir$entry")) {
                $retval[] = array(
                  "name" => "$dir$entry",
                  "type" => mime_content_type("$dir$entry"),
                  "size" => filesize("$dir$entry"),
                  "lastmod" => filemtime("$dir$entry")
                );
              }
            }
            $d->close();
        
            return $retval;
          }
          $dirGal = "assets/galeria/".$nomGal;
          $dirlist = getFileList($dirGal);
          echo "<div id='galslide' class='nivoSlider'>";
            foreach($dirlist as $file) {
              if(!preg_match("/\.jpg$/", $file['name'])) continue;
              //    echo "<img src='".$file['name']."'/>";
            $input = $file['name'];
            $width = 50;
            $height = 50;
            $options = "w=$width&height=$height&zc=1";   
            $thumbnail = $modx->runSnippet("phpthumbof",array('input' => $input, 'options' => $options));
            echo "<img src='".$input."' rel='".$thumbnail."'/>";
            }
          echo "</div>";
        

          • 42753
          • 17 Posts
          Quote from: Wanze at Dec 20, 2010, 12:38 PM
          Hi Eminos

          I think to use the runSnippet method should work.
          Try out the following.

           
          $input = "pathtoimage/image.jpg";
          $width = 200;
          $height = 50;
          $options = "w=$width&height=$height&zc=1";   
          $thumbnail = $modx->runSnippet("phpthumbof",array('input' => $input, 'options' => $options));
          


          The variable $thumbnail should now containing the path to your thumbnail image.
          I didn't test the code...

          Cheers

          Thank you, works fine except of the &zc=1. What may be the reason?
            • 5160
            • 118 Posts
            There is a typo in the arguments for $options, it should be:

            $options = "w=$width&h=$height&zc=1";