我见过很多其他的话题,我都试过了。有人能帮我解释一下为什么这个脚本不会上传PNG文件吗?正在显示空白PNG图像。
$image = $_FILES['file']['tmp_name'];
$image_name = $_FILES['file']['name'];
$ext = pathinfo($image_name, PATHINFO_EXTENSION);
$location = "Profiles/{$user}/Picture/{$image_name}";
$new_image = imagecreatetruecolor(100, 100);
$source_image = imagecreatefrompng($image);
imagealphablending($source_image, false);
imagesavealpha($source_image, true);
imagealphablending($new_image, false);
imagesavealpha($new_image, true);
imagecopyresampled($new_image, $image, 0, 0, 0, 0, 100, 100, $image_width, $image_height);
imagepng($new_image, '../' . $location, 9);发布于 2015-06-23 15:40:51
您不是在声明$image_width或$image-height,而是在imagecopyresampled()中引用$image而不是$source_image。
我也得到了一个普通的白色图像,但在这之后我得到了预期的结果:
$image = $_FILES['file']['tmp_name'];
$image_name = $_FILES['file']['name'];
$ext = pathinfo($image_name, PATHINFO_EXTENSION);
$location = "Profiles/{$user}/Picture/{$image_name}";
$new_image = imagecreatetruecolor(100, 100);
$source_image = imagecreatefrompng($image);
// Get the width & height of the uploaded image.
$image_width = imagesx($source_image);
$image_height = imagesy($source_image);
imagealphablending($source_image, false);
imagesavealpha($source_image, true);
imagealphablending($new_image, false);
imagesavealpha($new_image, true);
imagecopyresampled($new_image, $source_image, 0, 0, 0, 0, 100, 100, $image_width, $image_height);
imagepng($new_image, '../' . $location, 9);https://stackoverflow.com/questions/31006615
复制相似问题