Problem resizing pictures with php
<p>I use the function below to re-size pictures. But I tried it today and it kept giving me an error message that says that the name and path of the picture is not a valid resource although the name and path is quite correct.This is the function:</p>

<pre><code>function createthumb($name, $filename, $new_w, $new_h) {
    $system = explode(".", $name);
    if (preg_match("/jpeg|jpg|JPG/", $system[1])) {
        $src_img = imagecreatefromjpeg($name);
    }
    if (preg_match("/png/", $system[1])) {
        $src_img = imagecreatefrompng($name);
    }
    $old_x = imageSX($src_img);
    $old_y = imageSY($src_img);
    if ($old_x &gt; $old_y) {
        $thumb_w = $new_w;
        $thumb_h = $old_y * ($new_h / $old_x);
    }
    if ($old_x &lt; $old_y) {
        $thumb_w = $old_x * ($new_w / $old_y);
        $thumb_h = $new_h;
    }
    if ($old_x == $old_y) {
        $thumb_w = $new_w;
        $thumb_h = $new_h;
    }
    $dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
    imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
    if (preg_match("/png/", $system[1])) {
        imagepng($dst_img, $filename);
    } else {
        imagejpeg($dst_img, $filename);
    }
    imagedestroy($dst_img);
    imagedestroy($src_img);
}
</code></pre>

<p>I used it this way</p>

<pre><code>$path = "photos/".$row-&gt;pic_name;
createthumb($path, $path, 350, 180);
</code></pre>

<p>I want it to resize the picture and overwrite the original (source).</p>

<p>The <code>$row-&gt;pic_name</code> is from the the database and the problem is not from it.
I've been using the function  that way and it works but not this time, maybe I should try a better one?</p>

<p>Thanks for any suggestions.</p>
