title: Generate barcode and save image file
body: <p>I am generating one barcode image but I am not able to save that file in specific folder. I Just want to generate the image and save that image to folder without display in folder.
  Below i my code.</p>
  
  <p><strong>Class File: barcode.php</strong></p>
  
  <pre><code>&lt;?php
      class barcode {
  
          function __construct() {
  
          }
  
          public function generateBarcode($text = '', $size = '', $orientation = '', $code_type = '', $filepath) {
              $text = (isset($text) ? $text : "0");
              $size = (isset($size) ? $size : "20");
              $orientation = (isset($orientation) ? $orientation : "horizontal");
              $code_type = (isset($code_type) ? $code_type : "code128");
              $code_string = "";
  
              // Translate the $text into barcode the correct $code_type
              if (strtolower($code_type) == "code128") {
                  $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";
              } elseif (strtolower($code_type) == "code39") {
                  $code_array = array("0" =&gt; "111221211", "1" =&gt; "211211112", "2" =&gt; "112211112", "3" =&gt; "212211111", "4" =&gt; "111221112", "5" =&gt; "211221111", "6" =&gt; "112221111", "7" =&gt; "111211212", "8" =&gt; "211211211", "9" =&gt; "112211211", "A" =&gt; "211112112", "B" =&gt; "112112112", "C" =&gt; "212112111", "D" =&gt; "111122112", "E" =&gt; "211122111", "F" =&gt; "112122111", "G" =&gt; "111112212", "H" =&gt; "211112211", "I" =&gt; "112112211", "J" =&gt; "111122211", "K" =&gt; "211111122", "L" =&gt; "112111122", "M" =&gt; "212111121", "N" =&gt; "111121122", "O" =&gt; "211121121", "P" =&gt; "112121121", "Q" =&gt; "111111222", "R" =&gt; "211111221", "S" =&gt; "112111221", "T" =&gt; "111121221", "U" =&gt; "221111112", "V" =&gt; "122111112", "W" =&gt; "222111111", "X" =&gt; "121121112", "Y" =&gt; "221121111", "Z" =&gt; "122121111", "-" =&gt; "121111212", "." =&gt; "221111211", " " =&gt; "122111211", "$" =&gt; "121212111", "/" =&gt; "121211121", "+" =&gt; "121112121", "%" =&gt; "111212121", "*" =&gt; "121121211");
  
                  // Convert to uppercase
                  $upper_text = strtoupper($text);
  
                  for ($X = 1; $X &lt;= strlen($upper_text); $X++) {
                      $code_string .= $code_array[substr($upper_text, ($X - 1), 1)] . "1";
                  }
  
                  $code_string = "1211212111" . $code_string . "121121211";
              } elseif (strtolower($code_type) == "code25") {
                  $code_array1 = array("1", "2", "3", "4", "5", "6", "7", "8", "9", "0");
                  $code_array2 = array("3-1-1-1-3", "1-3-1-1-3", "3-3-1-1-1", "1-1-3-1-3", "3-1-3-1-1", "1-3-3-1-1", "1-1-1-3-3", "3-1-1-3-1", "1-3-1-3-1", "1-1-3-3-1");
  
                  for ($X = 1; $X &lt;= strlen($text); $X++) {
                      for ($Y = 0; $Y &lt; count($code_array1); $Y++) {
                          if (substr($text, ($X - 1), 1) == $code_array1[$Y])
                              $temp[$X] = $code_array2[$Y];
                      }
                  }
  
                  for ($X = 1; $X &lt;= strlen($text); $X+=2) {
                      if (isset($temp[$X]) &amp;&amp; isset($temp[($X + 1)])) {
                          $temp1 = explode("-", $temp[$X]);
                          $temp2 = explode("-", $temp[($X + 1)]);
                          for ($Y = 0; $Y &lt; count($temp1); $Y++)
                              $code_string .= $temp1[$Y] . $temp2[$Y];
                      }
                  }
  
                  $code_string = "1111" . $code_string . "311";
              } elseif (strtolower($code_type) == "codabar") {
                  $code_array1 = array("1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "$", ":", "/", ".", "+", "A", "B", "C", "D");
                  $code_array2 = array("1111221", "1112112", "2211111", "1121121", "2111121", "1211112", "1211211", "1221111", "2112111", "1111122", "1112211", "1122111", "2111212", "2121112", "2121211", "1121212", "1122121", "1212112", "1112122", "1112221");
  
                  // Convert to uppercase
                  $upper_text = strtoupper($text);
  
                  for ($X = 1; $X &lt;= strlen($upper_text); $X++) {
                      for ($Y = 0; $Y &lt; count($code_array1); $Y++) {
                          if (substr($upper_text, ($X - 1), 1) == $code_array1[$Y])
                              $code_string .= $code_array2[$Y] . "1";
                      }
                  }
                  $code_string = "11221211" . $code_string . "1122121";
              }
  
              // Pad the edges of the barcode
              $code_length = 20;
              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;
                  $img_height = $size;
              } else {
                  $img_width = $size;
                  $img_height = $code_length;
              }
  
              $image = imagecreate($img_width, $img_height);
              $black = imagecolorallocate($image, 0, 0, 0);
              $white = imagecolorallocate($image, 255, 255, 255);
  
              imagefill($image, 0, 0, $white);
  
              $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, 0, $cur_size, $img_height, ($position % 2 == 0 ? $white : $black));
                  else
                      imagefilledrectangle($image, 0, $location, $img_width, $cur_size, ($position % 2 == 0 ? $white : $black));
                  $location = $cur_size;
              }
  
              // Draw barcode to the screen
              header('Content-type: image/png');
              imagepng($image,'one.png');
              imagedestroy($image);
          }
  
      }
  ?&gt;
  </code></pre>
  
  <p><strong>Called method:</strong></p>
  
  <pre><code>    &lt;?php
      include('barcode.php');
      $barObj = new barcode();
      $barObj-&gt;generateBarcode('Praveen','vertical','40','C128','one.png');
  ?&gt;
  </code></pre>
  
  <p>I am getting error like "The image “<a href="http://example.com/index.php" rel="nofollow">http://example.com/index.php</a>” cannot be displayed because it contains errors."
  Please help, thanks in advance.</p>