title: How can we convert html tables in to png using GD library in PHP?
body: <p>I am trying to create a chessboard and save as png file. I have added the functionality to create a chessboard and store the image in to the <code>img</code> folder. Image is storing in to the folder but it is blank and html code is showing on image. I used GD Library. </p>
  
  <p>I have include my code, php gd library info &amp; image here. Any help would be appreciated.</p>
  
  <pre><code>&lt;?php
  $tableWidth = 150 . 'px';
  $width      = 20 . 'px';
  $height     = 20 . 'px';
  
  $image = "&lt;table width=".$tableWidth." style='margin-left: 200px;'&gt;";
  for($i=0; $i &lt; 8; $i++){
      $image .= "&lt;tr&gt;";
      for($j=0; $j &lt; 8; $j++){
          if($i % 2 == 0){
              if($j % 2 == 0){
                  $image .= '&lt;td style="background-color: pink; width: '.$width.'; height: '.$height.'"&gt;&lt;/td&gt;';
              } else {
                  $image .= '&lt;td style="background-color: black; width: '.$width.'; height: '.$height.'"&gt;&lt;/td&gt;';
              }
          } else {
              if($j % 2 == 0){
                  $image .= '&lt;td style="background-color: black; width: '.$width.'; height: '.$height.'"&gt;&lt;/td&gt;';
              } else {
                  $image .= '&lt;td style="background-color: pink; width: '.$width.'; height: '.$height.'"&gt;&lt;/td&gt;';
              }
          }
      }
      $image .= "&lt;/tr&gt;";
  }
  $image .= "&lt;table&gt;";
  
  $im               = @imagecreate(300, 600)
  or die("Cannot Initialize new GD image stream");
  $background_color = imagecolorallocate($im, 0, 0, 0);
  $text_color       = imagecolorallocate($im, 233, 14, 91);
  imagestring($im, 1, 5, 5,  $image, $text_color);
  //imagettftext($img, 9, 0, 1, 1, $white, "VERDANA.TTF", $html_code);
  header("Content-Type: image/png");
  imagepng($im, 'img/chessboard.png');
  ?&gt;
  </code></pre>
  
  <p>Present Result</p>
  
  <p><a href="https://i.stack.imgur.com/prSh8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/prSh8.png" alt="enter image description here"></a></p>
  
  <p>PHP Info</p>
  
  <pre><code>GD Support          enabled
  GD Version          bundled (2.1.0 compatible)
  FreeType Support    enabled
  FreeType Linkage    with freetype
  FreeType Version    2.9.1
  GIF Read Support    enabled
  GIF Create Support  enabled
  JPEG Support        enabled
  libJPEG Version     9 compatible
  PNG Support         enabled
  libPNG Version      1.6.34
  WBMP Support        enabled
  XPM Support         enabled
  libXpm Version      30512
  XBM Support         enabled
  WebP Support        enabled
  </code></pre>