We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 44195
    • 293 Posts
    Hi I'm looking for an example of how to use this to create a thumbnail in a sub-directory from my processor.

    For example, once the image is uploaded to the target dir, I've tried using modx->runSnippet('phpthumbsup', array('input'=>$filePath, 'options'=>'w=100&h=100'));
    but this doesn't seem to do anything.
    Is there a better way of going about it? What am I missing? smiley

    This question has been answered by muzzstick. See the first response.

      I'm lead developer at Digital Penguin Creative Studio in Hong Kong. https://www.digitalpenguin.hk
      Check out the MODX tutorial series on my blog at https://www.hkwebdeveloper.com
    • discuss.answer
      • 44195
      • 293 Posts
      Never mind, I just ended up going with modPhpThumb in the core.

      This is my function in my uploadImageProcessor

      private function generateThumbs($path) {
          
          // Check if landscape or portrait
          list($width, $height) = getimagesize($path);
          if ($width > $height) {
              
              // Landscape
              $thumbnail_widths = array(70, 320, 820);
              foreach ($thumbnail_widths as $thumbnail_width) {
                  $modPhpThumb = new modPhpThumb($this->modx);
                  $modPhpThumb->setSourceFilename($path); // original image
                  $modPhpThumb->setParameter('w', $thumbnail_width);
                  $modPhpThumb->setParameter('config_output_format', 'jpeg');
                  $output_filename = pathinfo($path,PATHINFO_DIRNAME).'/thumbnails/'.basename($path).'_'.$thumbnail_width.'.'.$modPhpThumb->config_output_format;
      
                  if ($modPhpThumb->GenerateThumbnail()) {
                      $modPhpThumb->RenderToFile($output_filename);
                  }
                  unset($modPhpThumb);
              }
          } else {
      
              // Portrait or Square
              $thumbnail_heights = array(50, 320, 680);
              foreach ($thumbnail_heights as $thumbnail_height) {
                  $modPhpThumb = new modPhpThumb($this->modx);
                  $modPhpThumb->setSourceFilename($path); // original image
                  $modPhpThumb->setParameter('h', $thumbnail_height);
                  $modPhpThumb->setParameter('config_output_format', 'jpeg');
                  $output_filename = pathinfo($path,PATHINFO_DIRNAME).'/thumbnails/'.basename($path).'_'.$thumbnail_height.'.'.$modPhpThumb->config_output_format;
                  if ($modPhpThumb->GenerateThumbnail()) {
                      $modPhpThumb->RenderToFile($output_filename);
                  }
                  unset($modPhpThumb);
              }
          }
      
      
      }
      
        I'm lead developer at Digital Penguin Creative Studio in Hong Kong. https://www.digitalpenguin.hk
        Check out the MODX tutorial series on my blog at https://www.hkwebdeveloper.com