这是我正在thumnbail脚本,它最终创建一个损坏的33字节图像。我认为问题出在exif_imagetype if语句中,但我不确定。我将不胜感激任何帮助。PHP创建腐败thumnbail
// 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);
}
有更多的代码?那个声明之后你在用$ canvas做什么? – mikevoermans 2012-03-30 22:29:49
那个图像里面有什么?也许这是33个符号的错误信息? – 2012-03-30 22:29:51
所有的代码都在那里,canvas被定义在if语句的正上方。是的,我相信有33个符号的错误。它始终认为任何图片都是PNG图片,这意味着即使它可能是JPG,它仍然无法通过第一次和第二次测试。 – Ramin 2012-03-30 22:34:29