I have a script which is supposed to take an image, resize it, then save it under the same name (replacing the old file) but instead, it saves an image which is solic black. My code is as follows;
define(IMAGE_BASE, 'images/');
define(MAX_WIDTH, 220);
define(MAX_HEIGHT, 220);
$image_path = IMAGE_BASE . "$location";
$img = null;
$ext = strtolower(end(explode('.', $image_path)));
if ($ext == 'jpg' || $ext == 'jpeg') {
$img = @imagecreatefromjpeg($image_path);
}
if ($img) {
$width = imagesx($img);
$height = imagesy($img);
$scale = min(MAX_WIDTH/$width, MAX_HEIGHT/$height);
if ($scale < 1) {
$new_width = floor($scale$width);
$new_height = floor($scale$height);
$img = imagecreate($new_width, $new_height);
imagecopyresized($img, $img, 0, 0, 0, 0, $new_width, $new_height, $width,
$height);
imagejpeg($img, $image_path);
$img_type = "JPG";
}
}
and $location is defined from a previous form linking to this page. Any ideas?