我有一个代码:
[(2, 4), (2, 6), (2, 8), (2, 10), (2, 12), (2, 14), (2, 16), (2, 18), (2, 20), (2, 22), (2, 24), (2, 26), (2, 28), (2, 30), (2, 32), (2, 34), (2, 36), (2, 38), (2, 40), (2, 42), (2, 44), (2, 46), (2, 48), (2, 50), (3, 6), (3, 9), (3, 12), (3, 15), (3, 18), (3, 21), (3, 24), (3, 27), (3, 30), (3, 33), (3, 36), (3, 39), (3, 42), (3, 45), (3, 48), (4, 8), (4, 12), (4, 16), (4, 20), (4, 24), (4, 28), (4, 32), (4, 36), (4, 40), (4, 44), (4, 48), (5, 10), (5, 15), (5, 20), (5, 25), (5, 30), (5, 35), (5, 40), (5, 45), (5, 50), (6, 12), (6, 18), (6, 24), (6, 30), (6, 36), (6, 42), (6, 48), (7, 14), (7, 21), (7, 28), (7, 35), (7, 42), (7, 49), (8, 16), (8, 24), (8, 32), (8, 40), (8, 48), (9, 18), (9, 27), (9, 36), (9, 45), (10, 20), (10, 30), (10, 40), (10, 50), (11, 22), (11, 33), (11, 44), (12, 24), (12, 36), (12, 48), (13, 26), (13, 39), (14, 28), (14, 42), (15, 30), (15, 45), (16, 32), (16, 48), (17, 34), (18, 36), (19, 38), (20, 40), (21, 42), (22, 44), (23, 46), (24, 48), (25, 50)]
它返回错误:
imagecreatefrompng():“ img / avatars / 6.png”在以下位置不是有效的PNG文件 W:\ domains \ mysite \ settings.php
我检查了它是png图片吗?
<?php
$size = 2000000;
$types = array('image/png', 'image/jpeg');
if(isset($_POST['go'])){
$newName = $id . '.' . $type;
$directory = 'img/avatars/'; //path to folder with images
$picture = $directory . basename($newName);
if (!in_array($_FILES['picture']['type'], $types)) {
die('Wrong type of file. <a href="../settings.php">Try another</a>');
} elseif ($_FILES['picture']['size'] > $size) {
die('File is too big. <a href="../settings.php">Try another</a>');
} elseif (move_uploaded_file($_FILES['picture']['tmp_name'], $picture)) {
echo "Image was downloaded!";
}
$new_width = 66; //necessary width
$size = getimagesize($picture);
$width = $size[0];
$height = $size[1];
if ($type == 'png') {
$src=ImageCreateFromPng($picture);
}
if ($type == 'jpeg' || $type == 'jpg') {
$src=ImageCreateFromJPEG($picture);
}
$coefficient = $width/$new_width;
$new_height = ceil($height/$coefficient);
$empty_picture = ImageCreateTrueColor($new_width, $new_height);
ImageCopyResampled($empty_picture, $src, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
if ($type == 'png') {
ImagePNG($empty_picture, $picture, -1);
}
if ($type == 'jpeg') {
ImageJPEG($empty_picture, $picture, -1);
}
imagedestroy($src);
}
?>
它返回我:image / png(是)。
所以我不知道这段代码有什么问题。感谢您的帮助!