gpt4 book ai didi

php - imagecreatefrompng 根本不起作用

转载 作者:可可西里 更新时间:2023-11-01 13:12:12 28 4
gpt4 key购买 nike

我已经用 mime 类型检查了文件。如果它是 jpg 或 gif,它可以与

完美配合
$src = imagecreatefromjpeg($tmpName);

$src = imagecreatefromgif($tmpName);

但是如果图片是png$src = imagecreatefrompng($tmpName);

src 变量在 png 情况下为空,但在 jpggif 中它显示为 资源id.

有人会告诉我我需要做什么吗?

$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $_FILES['photo']['tmp_name']);
unset($_FILES["photo"]["type"]);
$_FILES["photo"]["type"] = $mime;

if ((($_FILES["photo"]["type"] == "image/gif") || ($_FILES["photo"]["type"] == "image/jpeg") || ($_FILES["photo"]["type"] == "image/jpg") || ($_FILES["photo"]["type"] == "image/pjpeg") || ($_FILES["photo"]["type"] == "image/x-png") || ($_FILES["photo"]["type"] == "image/png")) && in_array($extension, $allowedExts)) {

if ($_FILES["photo"]["error"] > 0) {
echo "Error uploading file <a href='step-1.php'> Try again. </a>";
$image_check = 0;
exit;
} else {

$image_check = 1;
$fileName = $_FILES['photo']['name'];
$tmpName = $_FILES['photo']['tmp_name'];
$fileSize = $_FILES['photo']['size'];
$fileType = $_FILES['photo']['type'];
list($width1, $height1, $typeb, $attr) = getimagesize($tmpName);

//$filePath = $uploadDir . $fileName;

$size = filesize($_FILES['photo']['tmp_name']);

$ext = $_FILES["photo"]["type"];

if ($ext == 'image/jpeg' || $ext == 'image/jpg') {
$src = imagecreatefromjpeg($tmpName);
} else if ($ext == 'image/gif') {
$src = imagecreatefromgif($tmpName);
}
else if(($ext=='image/png')||($ext=='image/x-png'))
{
$src = imagecreatefrompng($tmpName);
}
$newwidth1 = 624;


$newheight1 = ($height1 * $newwidth1) / ($width1);
$tmp = imagecreatetruecolor($newwidth1, $newheight1);

imagecopyresampled($tmp, $src, 0, 0, 0, 0, $newwidth1, $newheight1, $width1, $height1);
$filename = "resources/images/" . $append . $_FILES['photo']['name'];

if ($ext == 'image/jpeg' || $ext == 'image/jpg') {
imagejpeg($tmp, $filename, 90);
} else if ($ext == 'image/gif') {
imagegif($tmp, $filename, 90);
}
else if(($ext=='image/png')||($ext=='image/x-png'))
{

imagepng($tmp, $filename, 90);
}

最佳答案

写一个文件

<?php
phpinfo();
?>

浏览它,你会看到JPG SupportGIF create Supportenabled但是PNG Support禁用

启用PNG 支持,它将起作用。

enter image description here

关于php - imagecreatefrompng 根本不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18821162/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com