php - 图片上传时背景为白色

标签 php html css

<分区>

不确定这是不是该问的地方,但我有一张我网站的图片,我在 powerpoint 上删除了它的背景,但是当我上传它时,它周围是白色背景。即使我将背景颜色设置为其他颜色,它也会有我选择的颜色以及它周围的白色。不知道如何摆脱白色,所以希望得到任何指导。

img {
  max-width: 50%;
}
<img src="https://jg-ross.000webhostapp.com/pageUploads/logo.png" style="background-color:red; padding:20px;">

我希望没有任何背景,当我在 powerpoint 上加载图像时没有白色,但是一旦我将它上传到我的网站,白色就在那里。

在存储它的图像文件夹中,图像周围还有一个白框,这是什么原因造成的,我可以摆脱它吗?

我是这样上传的,图片存储在sql表中:

<?php
    try {
    $stmt = $db->query('SELECT image_title, image FROM images WHERE id= 2 ');
    while($row = $stmt->fetch()){
    echo "<img src='pageUploads/".$row['image']."'height='50px'";
    }
}catch(PDOException $e) {
            echo $e->getMessage();
        }

?>

<?php
require_once('../includes/config.php');
$target_dir = "../pageUploads/";
$target_file = $target_dir . basename($_FILES["image"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {

            //collect form data
        extract($_POST);

    $check = getimagesize($_FILES["image"]["tmp_name"]);
    if($check !== false) {
        echo "File is an image - " . $check["mime"] . ".";
        $uploadOk = 1;
    } else {
        echo "File is not an image.";
        $uploadOk = 0;
    }
}
// Check if file already exists
if (file_exists($target_file)) {
    echo "Sorry, file already exists.";
    $uploadOk = 0;
}
// Check file size
if ($_FILES["image"]["size"] > 2000000) {
    echo "Sorry, your file is too large.";
    $uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
    echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
    $uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
    echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
    if (move_uploaded_file($_FILES["image"]["tmp_name"], $target_file)) {
        echo "The file ". basename( $_FILES["image"]["name"]). " has been uploaded.";
    } else {
        echo "Sorry, there was an error uploading your file.";
    }
}
        $upload =  basename( $_FILES["image"]["name"]);

            try {

                //insert into database
                $stmt = $db->prepare('INSERT INTO images (image_title,image) VALUES (:image_title, :image)') ;
                $stmt->execute(array(
                    ':image_title' => $image_title,
                    ':image' => $upload

                ));

                //redirect to index page
                header('Location: images.php?action=added');
                exit;

            } catch(PDOException $e) {
                echo $e->getMessage();
            }



?>

最佳答案

您正在使用 powerpoint 导出图像,powerpoint 不是图像编辑器。 PNG 可以在保存透明度的情况下保存,但您需要使用 Photoshop 之类的工具。

以这张图片为例,假设我们要去除黑色边框并使它们透明:

enter image description here

使用魔术橡皮擦工具删除边框

enter image description here enter image description here

下一步“保存为 web”并选择“透明度”

enter image description here

关于php - 图片上传时背景为白色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57706719/

相关文章:

php - 使用 PHPMailer 发送邮件时无法在主题中发送表情符号

php - 使用 DOM 解析 html

html - CSS 中的 "Show more/less"有问题

html - 如何CSS选择所有div到从具有ID的div向下的级别

html - 如何将图像放置在文本旁边并使用屏幕分辨率对其进行缩放

javascript - 单选按钮 - 使用 javascript 的图像 + 文本选择器

javascript - 通过javascript添加图像改变位置

javascript - 刷新另一个页面

php - 登录页面是否需要 cookie?

jQuery:定时在文本上运行动画