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 support/comment thread for <a href="http://modxcms.com/extras/package/566">TVimageResizer 1.6-release</a>.

    Use this forum to post any comments about this addition or any questions you have regarding its use.

    Brief Description:
    Resizing images of Template Variables
      • 20909
      • 19 Posts
      Thank you for this great Plugin!!

      I made a small modification. The Plugin now both resizes and crops an image to get a thumbnail which exactly matches the specified dimensions.


      Code:
      //<?php
      
      //***********************************
      //TVimageResizer plugin v1.6 for MODx 1.0
      //Used EasyPhpThumbnail class by JF Nutbroek
      //***********************************
      //Andchir  http://wdevblog.net.ru
      //***********************************
      //Modified 17. August 2009
      //When using dimensions for Thumbnails 
      //the plugin now automatically crops the image
      //to exactly fit the dimensions.
      //***********************************
      // Copy folder to assets/plugins/
      // Description: Resizing images of Template Variables. Rounding the corners, adding watermarks.
      // Configuration: &th_width=Width;int;150 &th_height=Height;int;110 &prefix=Prefix;string;t_ &rcorner=Corners percentage of clipping;int;0 &watermark=Watermark image path (png);string;0 &copyrighttext=Copyright text;string;0 &quality=Quality;int;85 
      // System Events: OnDocFormRender, OnBeforeDocFormSave
      //***********************************
      
      if(!isset($prefix)) $prefix="t_";
      if(!isset($th_width)) $th_width=100;
      if(!isset($th_height)) $th_height=100;
      if(!isset($rcorner)) $rcorner=false;
      if(!isset($watermark)) $watermark=false;
      if(!isset($watermarkPos)) $watermarkPos="90% 90%";
      if(!isset($copyrighttext)) $copyrighttext=false;
      if(!isset($quality)) $quality=85;
      if(!isset($square)) $square=true;
      if(!isset($bg_color)) $bg_color="#ffffff";
      
      global $content;
      global $tmplvars;
      
      $doc_id = $content['id'];
      $template = $content['template'];
      $fullpath = $modx->config['base_path'];
      define(IMAGE_CLASS,"GD");
      $e = &$modx->Event;
      $output = "";
      
      $tb_tmplvars = $modx->getFullTableName('site_tmplvars');
      $tb_tmplvar_values = $modx->getFullTableName('site_tmplvar_contentvalues');
      
      require_once('../assets/plugins/tvimageresizer/easyphpthumbnail.class.php');
      
      if ($e->name == 'OnDocFormRender') {
      
      $result = $modx->db->select('id,name', $tb_tmplvars, "type='image'");
      $tvs = '';
      
      while ($row = $modx->db->getRow($result))
        $tvs .= ",'" . $row['id'] . "'";
      
      $tvs = substr($tvs, 1); // removes starting comma
      
      $output = <<< EOT
      
      <!-- TVimageResizer -->
      <script type="text/javascript">
      
      var imageNames = [$tvs];
      
      window.onDomReady(function() {
          for (var i = 0; i < imageNames.length; i++) {
            var elem = $('tv' + imageNames[i])
            if (elem) {
              var field1 = new Element('input',{type:'checkbox', name:'rsz[]', id:'rsz'+(i+1), value:imageNames[i]});
              var label = new Element('label',{for:'rsz'+(i+1)});
              var field2 = new Element('input',{type:'text', size:'5', name:'rszwidth[]', value:$th_width, 'styles': {'width':'20px'}});
              var field3 = new Element('input',{type:'text', size:'5', name:'rszheight[]', value:$th_height, 'styles': {'width':'20px'}});
              elem.getParent().adopt(field1).adopt(label.appendText('resize')).adopt(field2).appendText('x','after').adopt(field3);
            }
        }
      });
      
      </script>
      <!-- /TVimageResizer -->
      
      EOT;
      
      $e->output($output);
      
      }
      
      if ($e->name == 'OnBeforeDocFormSave') {
      
          if(isset($_POST['rsz'])){
          echo $override_tv;
          foreach ($_POST['rsz'] as $k=>$v) {
            if(!empty($_POST['tv'.$v])){
              $s_value = $_POST['tv'.$v];
              $location = str_replace(basename($s_value),'',$s_value);
              $new_value = $location.$prefix.basename($s_value);
      
              if($s_value!=$new_value && !empty($s_value)){
                if(file_exists("../$new_value")) unlink("../$new_value");
      
                $th_width = $_POST['rszwidth'][$k] ? $_POST['rszwidth'][$k] : $th_width;
      	  $th_height = $_POST['rszheight'][$k] ? $_POST['rszheight'][$k] : $th_height;
      	    
      	  //***
            	  //Start modification
      	  $th_size = ($th_width<=$th_height) ? $th_height : $th_width;  
      
                $thumb = new easyphpthumbnail;
      	  $thumb -> Thumbsize = $th_size;
      	  $thumb -> Thumbheight = $th_size;
      	  $thumb -> Thumbwidth = $th_size;
      	  $thumb -> Backgroundcolor = $bg_color;
                $thumb -> Quality = 100;
                $thumb -> Thumblocation = "../".$location;
                $thumb -> Thumbprefix = $prefix;
                $thumb -> Createthumb("../$s_value","file");
      
      	  $s_value = $new_value;
      	  $prefix = ""; // overwrite temp-thumb
      
      	  $thumb -> Thumbheight = $th_height;
      	  $thumb -> Thumbwidth = $th_width;
      
                // Croppring images to exactly math specified dimensions
      	  $thumb -> Cropimage[0] = 2;
      	  $thumb -> Cropimage[1] = 1;
      	  $thumb -> Cropimage[2] = floor($th_width/2); // left from center
      	  $thumb -> Cropimage[3] = floor($th_width/2); // right from center
      	  $thumb -> Cropimage[4] = floor($th_height/2); // top from center
      	  $thumb -> Cropimage[5] = floor($th_height/2); // bottom from center
      
      	  if($th_width == $th_height) {
      	    // settings for squared Thumbnails
      	    $thumb -> Square = $square;	
      	  }
      	  //End modification
      	  //***
      
                if($rcorner)
                  $thumb -> Clipcorner = array(2,$rcorner,0,1,1,1,1);
                if($watermark){
                  $thumb -> Watermarkpng = $watermark;
                  $thumb -> Watermarktransparency = 60;
                  $thumb -> Watermarkposition = $watermarkPos;
                }
                if($copyrighttext)
                  $thumb -> Copyrighttext = $copyrighttext;
                $thumb -> Quality = $quality;
                $thumb -> Thumblocation = "../".$location;
                $thumb -> Thumbprefix = "$prefix";
                $thumb -> Createthumb("../$s_value","file");
                
                $tmplvars[$v][1] = $new_value;
              }
            }
          }
        }
      }
      
      //?>
      


      I hope I could help someone with it.
        • 15175
        • 116 Posts
        I can’t get this to work and am wondering what I am doing wrong.

        This is how I’ve set it up:

        - put folder "tvimageresizer" in asset/plugins
        - created new plugin called "TVimageResizer"
        - pasted in TVimageResizer_plugin_1.6.txt
        - pasted in configuration details
        - set System Events to OnDocFormRender, OnBeforeDocFormSave

        Am I missing something?

        Thanks.
          • 15175
          • 116 Posts
          Hi Andchir.

          Thanks for replying. I’m using Evolution 0.9.6.3 and Image TV’s.

          I’m sure it’s probably something quite simple I’m not doing.

            • 15175
            • 116 Posts
            I tried v1.5 - still no joy unfortunately.
              • 15175
              • 116 Posts
              OK, I’ve got it working by disabling ManagerManager and removing hyphens from my TV names.
                • 27421
                • 67 Posts
                I’m having the same problem, I can’t get it to work. I followed the directions, I’m running version 1.6 on Evo 1.0.
                  • 18339
                  • 14 Posts
                  Mark Scudder Reply #8, 17 years ago
                  Why is there absolutely no documentation anywhere for this anywhere?
                    • 1687
                    • 25 Posts
                    Me too, I can’t get it to work.

                    I’m running version 1.6 on Evo 1.0.

                    I have downloaded the php5 version of easyphpthumbnail here :
                    http://www.mywebmymail.com/?q=content/easyphpthumbnail-class

                    But the thumbnail is not generated with php4 nor php5...

                    Thanks for helping us
                      • 3534
                      • 6 Posts
                      That is how i got it to work, but I’m not sure if it’s 100% correct usage ;-)
                      so please do not consider it as genuine instructions.

                      1. Copy easyphpthumbnail.class.php file to assetes/plugins/tvimageresizer.
                      2. Create plugin TVimageResizer and copy content of txt file.
                      3. In plugin edit mode/plugin configuration paste sth like this:
                      &th_width=Max.width;int;150 &th_height=Max.height;int;110 &prefix=prefix;int;_t
                      4. In plugin edit mode/system events tab - check both: OnDocFormRender, OnBeforeDocFormSave.
                      5. Save - and now edit your document with a proper template/TV.

                      This way I got what screen capture shows on plugin’s download page.

                      I do not know how to use round corners, watermark.