小编use*_*448的帖子

上传和调整图像大小时Png黑色背景

你能帮我解决我的PHP代码吗?

我不知道如何使我的照片透明.上传后,它们具有黑色背景.我这里有代码.(以及一些小帖子和内容的文字)

谢谢你.

<?php
function zmensi_obrazok($image_max_width, $image_max_height, $obrazok, $obrazok_tmp, $obrazok_size, $filename){

$postvars          = array(
"image"            => $obrazok,
"image_tmp"        => $obrazok_tmp,
"image_size"       => $obrazok_size,
"image_max_width"  => $image_max_width,
"image_max_height" => $image_max_height
);

$valid_exts = array("jpg","jpeg","png");
$ext = end(explode(".",strtolower($obrazok)));
if($postvars["image_size"] <= 1024000){


if(in_array($ext,$valid_exts)){




if($ext == "jpg" || $ext == "jpeg"){
$image = imagecreatefromjpeg($postvars["image_tmp"]);
}
else if($ext == "png"){
$image = imagecreatefrompng($postvars["image_tmp"]);
}


list($width,$height) = getimagesize($postvars["image_tmp"]);


$old_width      = imagesx($image);
$old_height     = imagesy($image);
$scale          = min($postvars["image_max_width"]/$old_width, $postvars["image_max_height"]/$old_height);
$new_width      = ceil($scale*$old_width);
$new_height     = ceil($scale*$old_height);


$tmp = …
Run Code Online (Sandbox Code Playgroud)

html php upload image

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

html ×1

image ×1

php ×1

upload ×1