$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_heig
$filename = 'path/to/original/file.xxx'; // where xxx is file type (jpg, gif, or png)
$newfilename = 'path/to/resized/file.xxx'; // where xxx is file type (jpg, gif, or png)
$path_parts = pathinfo($filename);
if ($path_parts['extension'] == 'jpg') {
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagejpeg($image_p, $newfilename);
} elseif ($path_parts['extension'] == 'gif') {
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromgif($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagegif($image_p, $newfilename);
} elseif ($path_parts['extension'] == 'png') {
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefrompng($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagepng($image_p, $newfilename);
} else {
echo "Source file is not a supported image file type.";
}