I created a script that resizes images, and saves them to the server. Everything works, but i get a white screen instead of th original web page, what is up?
Here is the code 🙂
//load image from server
$image = open_image($_SERVER['DOCUMENT_ROOT'].'/'.$_POST['imageresize']);
//see it it is there
if ($image === false) { die ('Unable to open image' . $_SERVER['DOCUMENT_ROOT'].'/'.$_POST['imageresize']); }
// Get original width and height
$width = imagesx($image);
$height = imagesy($image);
// Set a new width, and calculate new height
$new_width = 200;
$new_height = $height * ($new_width/$width);
// Resample
$image_resized = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
// Display resized image and save it(hoepfully)
header('Content-Type: image/jpeg')
imagejpeg($image_resized,'../images/resizedimage.jpg');
imagedestroy($image_resized);
die();
function open_image ($file)
{
# JPEG:
$im = @imagecreatefromjpeg($file);
if ($im !== false) { return $im; }
# GIF:
$im = @imagecreatefromgif($file);
if ($im !== false) { return $im; }
# PNG:
$im = @imagecreatefrompng($file);
if ($im !== false) { return $im; }
# GD File:
$im = @imagecreatefromgd($file);
if ($im !== false) { return $im; }
# GD2 File:
$im = @imagecreatefromgd2($file);
if ($im !== false) { return $im; }
# WBMP:
$im = @imagecreatefromwbmp($file);
if ($im !== false) { return $im; }
# XBM:
$im = @imagecreatefromxbm($file);
if ($im !== false) { return $im; }
# XPM:
$im = @imagecreatefromxpm($file);
if ($im !== false) { return $im; }
# Try and load from string:
$im = @imagecreatefromstring(file_get_contents($file));
if ($im !== false) { return $im; }
return false;
}