my '.png' image not work for resize image code in php
<p>when i pass a jpg file to <code>imgsize.php?w=100&amp;h=100&amp;img=powered_by.jpg</code> then its work well
but i pass a png file to <code>imgsize.php?w=100&amp;h=100&amp;img=mengo.png</code> it's not working</p>

<p>my imgsize.php file code is</p>

<pre><code>$extension = pathinfo($_GET['img']);
$extension = $extension[extension];
if ($extension == "jpg" || $extension == "jpeg" || $extension == "JPG") {
    header("Content-type: image/jpeg");
}
if ($extension == "png") {
    header("Content-type: image/png");
}
if ($extension == "gif") {
    header("Content-type: image/gif");
}
$img     = $_GET['img'];
$nwidth  = $_GET['w'];
$nheight = $_GET['h'];
$img2    = imagecreatefromjpeg($_GET['img']);
$width   = imagesx($img2);
$height  = imagesy($img2);
$ratio   = $width / $height;
$new_nwidth  = $nwidth;
$new_nheight = floor($height * ($nwidth / $width));
$im = imagecreatefromjpeg($img) or $im = imagecreatefrompng($img) or $im = imagecreatefromgif($img) or $im = false;
if (!$im) {
} else {
    $thumb = imagecreatetruecolor($new_nwidth, $new_nheight);
    imagealphablending($thumb, false);
    imagesavealpha($thumb, true);
    $transparent = imagecolorallocatealpha($thumb, 255, 255, 255, 127);
    imagefilledrectangle($thumb, 0, 0, $new_nwidth, $new_nheight, $transparent);
    imagecopyresized($thumb, $im, 0, 0, 0, 0, $new_nwidth, $new_nheight, $width, $height);
    if ($extension == "jpg" || $extension == "jpeg" || $extension == "JPG") {
        imagejpeg($thumb, null, 100);
    }
    if ($extension == "png") {
        imagepng($thumb, null, 9);
    }
    if ($extension == "gif") {
        imagegif($thumb, null, 100);
    }
}
</code></pre>

<p>any solution for it ? its display blank image when i pass it out a png file</p>
