We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34162
    • 1 Posts
    This is an auto-generated topic for PHPThumbFilter 0.2-beta1 by jaredloman.

    Brief Description:

    This snippet allows you to use PHPThumb as an Output filter for image TV's
    Seems to work with all PHPThumb modifiers, but I haven't tried them all. I have a couple basic fool proof checks but it could use some improvement.
      • 14653
      • 24 Posts
      When you install this package, there is an error "An error occurred while connecting to the Provider: No package found."
        Sys. info:
        MODx version: MODx Revolution 2.x
        OS: Archlinux roller
        • 28215
        • 4,149 Posts
        It looks like the author didn’t upload the zip file, but something else.

        They need to upload the transport.zip file.
          shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
          • 14951
          • 151 Posts
          Super sorry about this..not sure what went wrong. I have re-uploaded to the extras section and will also attach here in case there is a wait for approval.

            • 7557
            • 61 Posts
            Hi!
            Jtech and others.
            The filter is very good. I did some changes, and included new features. I tried to comment on everything. Sorry for my English.
            
            <?php
            // PHPThumb Output Filter - The Dumb way (I'm sure)
              //
              // By Jared Loman a.k.a jtech - http://www.jaredloman.com
              //
              // Revision by Djordje Dimitrijev (dj13 on Modx forum)
              //
              // Revision Notes:
              //
              // Added possibility use or not high security password from phpThumb config.
              // Possibility to add as much as you want default image attributes through the array.     
              // New way to add attributes in filter:
              // attribute_html_name || attribute_value
              //
              // Example: [[*mytvImage:phpthumb=`&w=100&h=50&zc=1,class||myClass,title||myTitle,style||border: 1px solid #333`]]
              //
              // Version 0.2 beta
              //
              // Current Version Notes:
              // Added array to handle "class" & "alt" options with defaults.
              // Added a space removal fool-proof in case someone trys to skip the class and add an alt.
              // Added Readme
              // Still haven't tested all phpthumb modifiers.
              //
              // Previous Version Notes:
              // v.0.1: I haven't tested all of the phpthumb modifiers, but I think they should work
              
              // ReadMe:
              //
              // Notes:
              // I created the PHPThumb output filter so that I could have some flexibility with my images that an output modifier
              // couldn't offer me. This output filter is essentially useless for anything other than images (Obviously!), but  I
              // figured I'd at least mention this.
              //
              // This does not support PHPThumbs ability to create new images from nothing. It would be kind of silly to use a
              // TV and Output filter for this purpose anyhow.
              //
              // INSTRUCTIONS:
              // Step 1.) Create a TV with an input type of "IMAGE" and an output type of "TEXT".
              // Step 2.) Add an image to the TV.
              // Step 3.) Add your TV to your page content or template and modify in the format of the example.
              //
              // OPTIONS:
              // Option 1.) The first option is the phpthumb modifications. You can add any modifier that phpthumb supports. (AFIK)
              // Option 2.) Image Class (optional) - Supply a class for your image. Defaults to "phpthumb" if you don't put anything in.
              // Option 3.) Image Alt (optional) - Supply text for the alt tag. Defaults to "phpthumb" if you don't put anything in.
              //
              // IMPORTANT:
              // Options MUST be put in specified order!
              // You Must specify a class if you would like a custom ALT. (e.g. [[*myTV:phpthumb=`&w=100,My Alt Text`]] ) will
              // return <img src=".." class="MyAltText" alt="phpthumb" />.. Sorry, it's just the nature of the beast.
              //
              // TV Output Type MUST be "TEXT"!!
              //
              // Example: [[*mytvImage:phpthumb=`&w=100&h=50&zc=1,imgClass,imgAlt`]]
             
              $phpthumb_path = 'assets/components/phpthumb';
              
              // Define attribute name - value separator
              $attribute_sep = '||';
              
              $base = $modx->config['base_url'];
              
              // Default array of attributes with key name like html attribute name. Lowercase for keys.
              // Examples:
              // $attributes['style'] = 'border:1px solid #ccc;'
              // $attributes['title'] = 'My Title';
              // $attributes['class'] = 'myClass'; 
              
              $error = "You need to specify at least one option, otherwise this filter is pointless!";
              if(!empty($options)){$phpthmbOptions = explode(",", $options);}else{$output = $error; return $output;}
              
              // Include phpThumb config file.
              require_once($modx->getOption('base_path') . $phpthumb_path . '/phpThumb.config.php');
            
              if(isset($PHPTHUMB_CONFIG['high_security_password'])) $_SESSION['high_security_password'] = $PHPTHUMB_CONFIG['high_security_password'];
              if(isset($PHPTHUMB_CONFIG['high_security_enabled'])) $_SESSION['high_security_enabled'] = $PHPTHUMB_CONFIG['high_security_enabled'];
              
              $att_out = '';
              $src = '';
              
              foreach($phpthmbOptions as $k => $v){
                
                // Skip phpThumb modifications
                if($k==0) continue;
                
                // Explode rest of options
                $m = explode($attribute_sep, $v);  
                
                $m_att = strtolower(trim($m[0]));
            
                // Join attributes except src 
                $att_out .= ' '.$m_att.'="'.trim($m[1]).'"';
                
                // Remove default attribute if exist in phpThumb options
                if(isset($attributes[$m_att])) unset($attributes[$m_att]);
              }
              
              // Add rest of unused default attributes 
              if(isset($attributes)) {
                  foreach($attributes as $k => $v){
                      $att_out .= ' '.$k.'="'.$v.'"'; 
                  } 
              }
              
              // Image url + phpthumb modifications
              $src = 'src=' . $base . $input . $phpthmbOptions[0];
              
              // If high security is enabled define hash
              if($_SESSION['high_security_enabled']){
                $output = $base . $phpthumb_path . '/phpThumb.php?' . $src . '&hash=' . md5($src.$_SESSION['high_security_password']);
              } else {
                $output = $base . $phpthumb_path . '/phpThumb.php?' . $src;
              }
             
              // Final join
              $output = '<img src="' . $output .'"'. $att_out.'>'; 
              return $output;  
             
            ?>
            
            
              • 7557
              • 61 Posts
              Hi.
              You can call this phpthumb filter like regular snippet, if You want show image from other resources. Somethilg like this (revision code):
              [[phpthumb? &input=`[[getResourceField? &id=`33` &field=`imageTV` &isTV=`1`]]` &options=`&w=100&h=50&zc=1,class||myClass,title||myTitle,style||border: 1px solid #333`]]
              
                • 14951
                • 151 Posts
                Awesome additions DJ13! I’ll add these to the main package and github. Wish I had your skills smiley
                  • 7557
                  • 61 Posts
                  Quote from: jtech at Aug 28, 2010, 08:14 PM

                  Awesome additions DJ13! I’ll add these to the main package and github. Wish I had your skills smiley
                  Thanks Jtech wink

                  I just add one more possibility. Choose the output from a script. Full image tag or only src value.

                  
                  <?php
                  // PHPThumb Output Filter - The Dumb way (I'm sure)
                    //
                    // By Jared Loman a.k.a jtech - http://www.jaredloman.com
                    //
                    // Revision by Djordje Dimitrijev (dj13 on Modx forum)
                    //
                    // Revision Notes:
                    //
                    // Choose the output from a script:
                    // 1. Full image tag.
                    // 2. Only src value (additional attributes will not be used).
                    // Added possibility use or not high security password from phpThumb config.
                    // Possibility to add as much as you want default image attributes through the array.     
                    // New way to add attributes in filter:
                    // attribute_html_name || attribute_value
                    //
                    // Examples:
                    //
                    // Filter full image tag: [[*mytvImage:phpthumb=`&w=100&h=50&zc=1,class||myClass,title||myTitle,style||border: 1px solid #333`]]
                    // Filter only src output: [[*mytvImage:phpthumb=`&w=100&h=50&zc=1,onlysrc||1`]]
                    //
                    // Snippet full image tag: [[phpthumb? &input=`files/myImage.jpg` &options=`&w=100&h=50&zc=1,class||myClass,title||myTitle`]]
                    // Snippet only src output v1 (best way if You want only src): [[phpthumb? &input=`files/myImage.jpg` &options=`&w=100&h=50&zc=1` &onlysrc=`1`]]
                    // Snippet only src output v2: [[phpthumb? &input=`files/myImage.jpg` &options=`&w=100&h=50&zc=1,onlysrc||1`]]
                    //
                    // Version 0.2 beta
                    //
                    // Current Version Notes:
                    // Added array to handle "class" & "alt" options with defaults.
                    // Added a space removal fool-proof in case someone trys to skip the class and add an alt.
                    // Added Readme
                    // Still haven't tested all phpthumb modifiers.
                    //
                    // Previous Version Notes:
                    // v.0.1: I haven't tested all of the phpthumb modifiers, but I think they should work
                    
                    // ReadMe:
                    //
                    // Notes:
                    // I created the PHPThumb output filter so that I could have some flexibility with my images that an output modifier
                    // couldn't offer me. This output filter is essentially useless for anything other than images (Obviously!), but  I
                    // figured I'd at least mention this.
                    //
                    // This does not support PHPThumbs ability to create new images from nothing. It would be kind of silly to use a
                    // TV and Output filter for this purpose anyhow.
                    //
                    // INSTRUCTIONS:
                    // Step 1.) Create a TV with an input type of "IMAGE" and an output type of "TEXT".
                    // Step 2.) Add an image to the TV.
                    // Step 3.) Add your TV to your page content or template and modify in the format of the example.
                    //
                    // OPTIONS:
                    // Option 1.) The first option is the phpthumb modifications. You can add any modifier that phpthumb supports. (AFIK)
                    // Option 2.) Image Class (optional) - Supply a class for your image. Defaults to "phpthumb" if you don't put anything in.
                    // Option 3.) Image Alt (optional) - Supply text for the alt tag. Defaults to "phpthumb" if you don't put anything in.
                    //
                    // IMPORTANT:
                    // Options MUST be put in specified order!
                    // You Must specify a class if you would like a custom ALT. (e.g. [[*myTV:phpthumb=`&w=100,My Alt Text`]] ) will
                    // return <img src=".." class="MyAltText" alt="phpthumb" />.. Sorry, it's just the nature of the beast.
                    //
                    // TV Output Type MUST be "TEXT"!!
                    //
                    // Example: [[*mytvImage:phpthumb=`&w=100&h=50&zc=1,imgClass,imgAlt`]]
                   
                    $phpthumb_path = 'assets/components/phpthumb';
                    
                    // Define attribute name - value separator
                    $attribute_sep = '||';
                    
                    $base = $modx->config['base_url'];
                    
                    // Default array of attributes with key name like html attribute name. Lowercase for keys.
                    // Examples:
                    // $attributes['style'] = 'border:1px solid #ccc;'
                    // $attributes['title'] = 'My Title';
                    // $attributes['class'] = 'myClass';
                    //
                    // IMPORTANT! If You set:
                    // $output_onlysrc = 1;
                    // all returns from snippet will be only src
                    
                    $output_onlysrc = false;
                    
                    $error = "You need to specify at least one option, otherwise this filter is pointless!";
                    if(!empty($options)){$phpthmbOptions = explode(",", $options);}else{$output = $error; return $output;}
                    
                    // Include phpThumb config file.
                     require_once($modx->getOption('base_path') . $phpthumb_path . '/phpThumb.config.php');
                    
                    if(isset($PHPTHUMB_CONFIG['high_security_password'])) $_SESSION['high_security_password'] = $PHPTHUMB_CONFIG['high_security_password'];
                    if(isset($PHPTHUMB_CONFIG['high_security_enabled'])) $_SESSION['high_security_enabled'] = $PHPTHUMB_CONFIG['high_security_enabled'];
                    
                    $att_out = '';
                    $src = '';
                    
                    // From snippet call
                    if($onlysrc == 1) {
                      $output_onlysrc = 1;
                    }
                    
                    // If onlysrc is set in snippet call or as default skip secound explode and adding rest of attributes
                    if($output_onlysrc !=1 ) {
                      
                      foreach($phpthmbOptions as $k => $v){
                        
                        // Skip phpThumb modifications
                        if($k==0) continue;
                        
                        // Explode rest of options
                        $m = explode($attribute_sep, $v);  
                        
                        $m_att = strtolower(trim($m[0]));
                        
                        // Search for onlysrc in options
                        if($m_att=='onlysrc' && trim($m[1])==1) {
                          $output_onlysrc = 1;
                          break;
                        }
                    
                        // Join attributes except src
                        $att_out .= ' '.$m_att.'="'.trim($m[1]).'"';
                        
                        // Remove default attribute if exist in phpThumb options
                        if(isset($attributes[$m_att])) unset($attributes[$m_att]);
                      }
                      
                      // Add rest of unused default attributes
                      if(isset($attributes)) {
                          foreach($attributes as $k => $v){
                              $att_out .= ' '.$k.'="'.$v.'"';
                          }
                      }
                    }
                    
                    // Image url + phpthumb modifications
                    $src = 'src=' . $base . $input . $phpthmbOptions[0];
                  
                    // If high security is enabled define hash
                    if($_SESSION['high_security_enabled']){
                      $output = $base . $phpthumb_path . '/phpThumb.php?' . $src . '&hash=' . md5($src.$_SESSION['high_security_password']);
                    } else {
                      $output = $base . $phpthumb_path . '/phpThumb.php?' . $src ;
                    }
                    
                    // Final join and output only src or full image tag
                    if($output_onlysrc ==1) {
                      return $output;
                    } else {
                      $output = '<img src="' . $output .'"'. $att_out.'>';
                      return $output;
                    }
                  ?>
                  
                  
                    • 14951
                    • 151 Posts
                    Hey DJ13,

                    Great work again! I just re-submitted the package to the modx repo with your last changes. What might be a practical use of only outputting the image source as opposed to just calling the TV unaltered by scripts? Flexibility is always nice, but I’m a bit slow today so I’m having trouble thinking of a way to use the "source only" feature.

                    Perhaps I can pick your brain a little bit on something.. The last feature that this snippet is missing is the ability to connect to the phpthumb installation that is already a part of modx. My original implementation of including the whole phpthumb script is a bit bulky and unnecessary. Thankfully phpthumb is a light weight script so it isn’t too big of a deal, but it would be nice to utilize what is already available (similar to Gallery).

                    I have been studying the modx docs trying to familiarize myself with "connectors" (I think they are what is needed?) but haven’t figured out much. Do you have any ideas on how to accomplish this?

                    Again, great work! It is really neat to see little ideas grow into useful products when placed in the hands of an excellent community!
                      • 7557
                      • 61 Posts
                      Quote from: jtech at Aug 30, 2010, 12:15 PM

                      Hey DJ13,

                      Great work again! I just re-submitted the package to the modx repo with your last changes. What might be a practical use of only outputting the image source as opposed to just calling the TV unaltered by scripts? Flexibility is always nice, but I’m a bit slow today so I’m having trouble thinking of a way to use the "source only" feature.

                      Perhaps I can pick your brain a little bit on something.. The last feature that this snippet is missing is the ability to connect to the phpthumb installation that is already a part of modx. My original implementation of including the whole phpthumb script is a bit bulky and unnecessary. Thankfully phpthumb is a light weight script so it isn’t too big of a deal, but it would be nice to utilize what is already available (similar to Gallery).

                      I have been studying the modx docs trying to familiarize myself with "connectors" (I think they are what is needed?) but haven’t figured out much. Do you have any ideas on how to accomplish this?

                      Again, great work! It is really neat to see little ideas grow into useful products when placed in the hands of an excellent community!

                      Choice only source would be useful to dynamically create Java script (maybe and CSS) when is not needed the entire image tag, but only the source of the image.
                      I’m new into Modx world, and also study the documentation.I do not know how, and whether it is possible to utilize integrated MODx phpthumb. If anyone knows please help.
                      I agree with You about the community. Thank You for your support.