Php imagecopyresampled将图像转换为黑色
上传后,我试图调整图像大小,但图像始终转换为黑色。虽然图像的尺寸正确,但它只显示黑色。我不知道我在哪里搞砸了。我已经找过了,所以没有用Php imagecopyresampled将图像转换为黑色,php,Php,上传后,我试图调整图像大小,但图像始终转换为黑色。虽然图像的尺寸正确,但它只显示黑色。我不知道我在哪里搞砸了。我已经找过了,所以没有用 if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $full_path)){ $orig_image = imagecreatefromjpeg($full_path); $image_info = getimagesize($full_path);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $full_path)){
$orig_image = imagecreatefromjpeg($full_path);
$image_info = getimagesize($full_path);
$width_orig = $image_info[0]; // current width as found in image file
$height_orig = $image_info[1]; // current height as found in image file
if($width_orig > $height_orig){
$width = 105;
$ratio = $width/$width_orig;
$height = $height_orig*$ratio;
}else{
$height = 360;
$ratio = $height/$height_orig;
$width = $width_orig*$ratio;
}
$destination_image = imagecreatetruecolor($width, $height);
imagecopyresampled($destination_image, $orig_image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
imagejpeg($destination_image, $full_path, 100);
}
在函数imagecreatefromjpeg()为舒尔之前检查图像类型。 大概是这样的:
$image_type = exif_imagetype($full_path);
switch ($image_type)
{
case IMAGETYPE_GIF : $orig_image = imagecreatefromgif($file); break;
case IMAGETYPE_JPEG : $orig_image = imagecreatefromjpeg($file); break;
case IMAGETYPE_PNG : $orig_image = imagecreatefrompng($file); break;
//...
default: echo 'Wrong image type'; break;
}
在函数imagecreatefromjpeg()为舒尔之前检查图像类型。 大概是这样的:
$image_type = exif_imagetype($full_path);
switch ($image_type)
{
case IMAGETYPE_GIF : $orig_image = imagecreatefromgif($file); break;
case IMAGETYPE_JPEG : $orig_image = imagecreatefromjpeg($file); break;
case IMAGETYPE_PNG : $orig_image = imagecreatefrompng($file); break;
//...
default: echo 'Wrong image type'; break;
}
imagecopyresampled
是否返回TRUE或FALSE?如果返回FALSE,则表示存在某种失败。@BenVisness返回FALSE。我不知道故障在哪里。imagecreatefromjpeg
返回什么?首先,我要验证顶部的四个变量是否都具有您期望的值。imagecopyresampled
是否返回TRUE或FALSE?如果返回FALSE,则表示存在某种失败。@BenVisness返回FALSE。我不知道故障在哪里。imagecreatefromjpeg
返回什么?首先,我要验证顶部的四个变量是否都具有您期望的值。已经有了,但仍然存在。如果有帮助,imagecopyresampled将返回false。我不知道为什么。我已经做了,但它仍然存在。如果有帮助,imagecopyresampled将返回false。我不知道为什么。