Save a squared thumbnail of uploaded image file in PHP
<p>I am attempting to create and save a squared version (thumb) of an uploaded image file with php. My current script crops it as it should, but the image is completely black. Here is my code:</p>

<pre><code>if ($_FILES['profile_pic']['type'] == "image/png") {
                            $is_image = true;
                            $newImage = imagecreatefrompng($img);
                        } else if ($_FILES['profile_pic']['type'] == "image/jpeg") {
                            $is_image = true;
                            $newImage = imagecreatefromjpeg($img);
                        } else if ($_FILES['profile_pic']['type'] == "image/gif") {
                            $is_image = true;
                            $newImage = imagecreatefromgif($img);
                        } else {
                            $is_image = false;
                        }
                        $img         = $_FILES["profile_pic"]['tmp_name'];
                        $min_width   = 100;
                        $min_height  = 100;
                        $width       = 0;
                        $height      = 0;
                        if ($is_image) {
                            list($width, $height) = getimagesize($img);
                        }

                        if ($is_image &amp;&amp; $height &gt;= $min_height &amp;&amp; $width &gt;= $min_width) {
                            $img         = $_FILES["profile_pic"]['tmp_name'];
                            $imgPath     = "../img/profile_pics/{$member_id}.png";

                            // Resize
                            $aspect_ratio = $width / $min_width;
                            $new_height = $height * $aspect_ratio;
                            $canvas1 = imagecreatetruecolor($min_width, $new_height);
                            imagecopyresampled($canvas1, $newImage, 0, 0, 0, 0, $min_width, $new_height, $width, $new_height);

                            // Crop
                            $canvas2 = imagecreatetruecolor($min_width, $min_height);
                            imagecopyresampled($canvas2, $newImage, 0, 0, 0, 0, $min_width, $min_height, $min_width, $min_height);
                            imagejpeg($canvas2, $imgPath, 80);
                            imagedestroy($canvas1);

                        }
</code></pre>

<p>I realise that there this question has been asked before, but for some reason I can't seem to make my own script work.</p>