title: Generating thumbnails - unwanted black background
body: <p>I use this script to resize picture from original size to thumbnail:</p>
  
  <pre><code>&lt;?php
  
  function resize($newWidth, $originalFile, $targetFile) {
  
  $info = getimagesize($originalFile);
  
  $mime = $info['mime'];
  
  switch ($mime) {
          case 'image/jpeg':
                  $image_create_func = 'imagecreatefromjpeg';
                  $image_save_func = 'imagejpeg';
                  $new_image_ext = 'jpg';
                  break;
  
          case 'image/png':
                  $image_create_func = 'imagecreatefrompng';
                  $image_save_func = 'imagepng';
                  $new_image_ext = 'png';
                  break;
  
          case 'image/gif':
                  $image_create_func = 'imagecreatefromgif';
                  $image_save_func = 'imagegif';
                  $new_image_ext = 'gif';
                  break;
  
          default: 
                  throw Exception('Unknown image type.');
  }
  
  
  $img = $image_create_func($targetFile,100);
  $width = $info[0];
  $height = $info[1];
  $newHeight = ($height / $width) * $newWidth;
  $tmp = imagecreatetruecolor($newWidth, $newHeight);
  imagecopyresampled($tmp, $img, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
  
  if (file_exists($targetFile)) {
          unlink($targetFile);
  }
  
  $image_save_func($tmp, $targetFile);
  
  echo "&lt;img src='$targetFile'&gt;";
  
  }
  
  ?&gt;
  </code></pre>
  
  <p>...and</p>
  
  <pre><code>&lt;?php
  
  echo "&lt;pre&gt;"; var_dump(gd_info()); echo "&lt;/pre&gt;";
  
  ?&gt;
  </code></pre>
  
  <p>returns:</p>
  
  <pre><code>array(12) {
  ["GD Version"]=&gt;
  string(26) "bundled (2.1.0 compatible)"
  ["FreeType Support"]=&gt;
  bool(true)
  ["FreeType Linkage"]=&gt;
  string(13) "with freetype"
  ["T1Lib Support"]=&gt;
  bool(true)
  ["GIF Read Support"]=&gt;
  bool(true)
  ["GIF Create Support"]=&gt;
  bool(true)
  ["JPEG Support"]=&gt;
  bool(true)
  ["PNG Support"]=&gt;
  bool(true)
  ["WBMP Support"]=&gt;
  bool(true)
  ["XPM Support"]=&gt;
  bool(true)
  ["XBM Support"]=&gt;
  bool(true)
  ["JIS-mapped Japanese Font Support"]=&gt;
  bool(false)
  }
  </code></pre>
  
  <p>...but it generates thumbs with black backgrounds. No errors or warnings are displayed. Display errors is set to "on". All images I'm testing with now are .jpg formats. Please, what am I doing wrong?</p>