title: How to generate fix size of barcode whether it's 3 char or 8 char?
body: <p>I am using one of third party class file to generate barcode with php dynamically as per user inputs. I have problem with it's variable size of width.</p>
  
  <p>When user enters 3 char then it creates small width of barcode and when user enters 10-14 chars, then it generates big barcode in width. I want barcode with same height - width in all cases. </p>
  
  <p>See my app details:</p>
  
  <ul>
  <li>PHP 5.6 </li>
  <li>CI3 framework</li>
  <li>barcode type : code128</li>
  </ul>
  
  <p>Please see my code below:</p>
  
  <pre><code>public function barcode( $filepath="", $text="USPC", $size="43", $orientation="horizontal", $code_type="code128", $print=false, $SizeFactor=1 ) {
      $code_string = "";
  
  $chksum = 104;
          // Must not change order of array elements as the checksum depends on the array's key to validate final code
          $code_array = array(" "=&gt;"212222","!"=&gt;"222122","\""=&gt;"222221","#"=&gt;"121223","$"=&gt;"121322","%"=&gt;"131222","&amp;"=&gt;"122213","'"=&gt;"122312","("=&gt;"132212",")"=&gt;"221213","*"=&gt;"221312","+"=&gt;"231212",","=&gt;"112232","-"=&gt;"122132","."=&gt;"122231","/"=&gt;"113222","0"=&gt;"123122","1"=&gt;"123221","2"=&gt;"223211","3"=&gt;"221132","4"=&gt;"221231","5"=&gt;"213212","6"=&gt;"223112","7"=&gt;"312131","8"=&gt;"311222","9"=&gt;"321122",":"=&gt;"321221",";"=&gt;"312212","&lt;"=&gt;"322112","="=&gt;"322211","&gt;"=&gt;"212123","?"=&gt;"212321","@"=&gt;"232121","A"=&gt;"111323","B"=&gt;"131123","C"=&gt;"131321","D"=&gt;"112313","E"=&gt;"132113","F"=&gt;"132311","G"=&gt;"211313","H"=&gt;"231113","I"=&gt;"231311","J"=&gt;"112133","K"=&gt;"112331","L"=&gt;"132131","M"=&gt;"113123","N"=&gt;"113321","O"=&gt;"133121","P"=&gt;"313121","Q"=&gt;"211331","R"=&gt;"231131","S"=&gt;"213113","T"=&gt;"213311","U"=&gt;"213131","V"=&gt;"311123","W"=&gt;"311321","X"=&gt;"331121","Y"=&gt;"312113","Z"=&gt;"312311","["=&gt;"332111","\\"=&gt;"314111","]"=&gt;"221411","^"=&gt;"431111","_"=&gt;"111224","\`"=&gt;"111422","a"=&gt;"121124","b"=&gt;"121421","c"=&gt;"141122","d"=&gt;"141221","e"=&gt;"112214","f"=&gt;"112412","g"=&gt;"122114","h"=&gt;"122411","i"=&gt;"142112","j"=&gt;"142211","k"=&gt;"241211","l"=&gt;"221114","m"=&gt;"413111","n"=&gt;"241112","o"=&gt;"134111","p"=&gt;"111242","q"=&gt;"121142","r"=&gt;"121241","s"=&gt;"114212","t"=&gt;"124112","u"=&gt;"124211","v"=&gt;"411212","w"=&gt;"421112","x"=&gt;"421211","y"=&gt;"212141","z"=&gt;"214121","{"=&gt;"412121","|"=&gt;"111143","}"=&gt;"111341","~"=&gt;"131141","DEL"=&gt;"114113","FNC 3"=&gt;"114311","FNC 2"=&gt;"411113","SHIFT"=&gt;"411311","CODE C"=&gt;"113141","FNC 4"=&gt;"114131","CODE A"=&gt;"311141","FNC 1"=&gt;"411131","Start A"=&gt;"211412","Start B"=&gt;"211214","Start C"=&gt;"211232","Stop"=&gt;"2331112");
          $code_keys = array_keys($code_array);
          $code_values = array_flip($code_keys);
          for ( $X = 1; $X &lt;= strlen($text); $X++ ) {
              $activeKey = substr( $text, ($X-1), 1);
              $code_string .= $code_array[$activeKey];
              $chksum=($chksum + ($code_values[$activeKey] * $X));
          }
          $code_string .= $code_array[$code_keys[($chksum - (intval($chksum / 103) * 103))]];
          $code_string = "211214" . $code_string . "2331112";
      $code_length = 20;
      if ($print) {
          $text_height = 30;
      } else {
          $text_height = 0;
      }
  
      for ( $i=1; $i &lt;= strlen($code_string); $i++ ){
          $code_length = $code_length + (integer)(substr($code_string,($i-1),1));
          }
  
      if ( strtolower($orientation) == "horizontal" ) {
          $img_width = $code_length*$SizeFactor;
          $img_height = 192;
          $img_width=384;// set hardcoded height -width as client suggested
      } else {
          $img_width = 384;
          $img_height = $code_length*$SizeFactor;
      }
  
      $image = imagecreate($img_width, $img_height + $text_height);
      $black = imagecolorallocate ($image, 0, 0, 0);
      $white = imagecolorallocate ($image, 255, 255, 255);
  
      imagefill( $image, 0, 0, $white );
      if ( $print ) {
          imagestring($image, 5, 31, $img_height, $text, $black );
      }
  
      $location = 10;
      for ( $position = 1 ; $position &lt;= strlen($code_string); $position++ ) {
          $cur_size = $location + ( substr($code_string, ($position-1), 1) );
          if ( strtolower($orientation) == "horizontal" )
              imagefilledrectangle( $image, $location*$SizeFactor, 0, $cur_size*$SizeFactor, $img_height, ($position % 2 == 0 ? $white : $black) );
          else
              imagefilledrectangle( $image, 0, $location*$SizeFactor, $img_width, $cur_size*$SizeFactor, ($position % 2 == 0 ? $white : $black) );
          $location = $cur_size;
      }
  // Draw barcode to the screen or save in a file
      if ( $filepath=="" ) {
          header ('Content-type: image/png');
          imagepng($image);
          imagedestroy($image);
      } else {
          imagepng($image,$filepath);
          imagedestroy($image);       
      }
  }
  </code></pre>
  
  <p>Can this be achieved?</p>