This is the thumnbail script I’m working on and it ends up creating a corrupt 33 byte image. I think the problem is in the exif_imagetype if statement but I’m not sure. I would appreciate any help.
// Original image
$filename = 'images/T' . $neutralName;
// Get dimensions of the original image
list($current_width, $current_height) = getimagesize($filename);
// The x and y coordinates on the original image where we
// will begin cropping the image
$left = 10;
$top = 5;
// This will be the final size of the image (e.g. how many pixels
// left and down we will be going)
$crop_width = 140;
$crop_height = 100;
// Resample the image
$canvas = imagecreatetruecolor($crop_width, $crop_height);
if ((exif_imagetype($_FILES['photo']['tmp_name'])) == IMAGETYPE_JPEG) {
$current_image = imagecreatefromjpeg($filename);
imagecopy($canvas, $current_image, 0, 0, $left, $top, $current_width, $current_height);
imagejpeg($canvas, $filename, 100);
} else if ((exif_imagetype($_FILES["photo"]['tmp_name'])) == IMAGETYPE_GIF) {
$current_image = imagecreatefromgif($filename);
imagecopy($canvas, $current_image, 0, 0, $left, $top, $current_width, $current_height);
imagegif($canvas, $filename, 100);
} else {
$current_image = imagecreatefrompng($filename);
imagecopy($canvas, $current_image, 0, 0, $left, $top, $current_width, $current_height);
imagepng($canvas, $filename, 100);
}
I think your problem is you’re trying to open an image that doesn’t exist or isn’t an image… In each of your each, you’re finding the file type via
$_FILES["photo"]['tmp_name']but directly below that if the condition is true, you’re usingimagecreatefromXXX($filename). Shouldn’t you be opening the image file that was uploaded and not the path to which you’re saving the image? Opening the path$filename(assuming it exists) would always copy the same exact square and save it. Doesn’t seem like a viable thing you’d be doing.