我使用以下代码调整图片大小。当上传透明图像(png / gif)时,创建的新图像具有黑色背景。如何在调整大小后使背景变白?请帮忙
$info = pathinfo($_FILES['file']['name']);
$ext = $info['extension']; // get the extension of the file
$newname = "testing".".".$ext;
$target = 'uploads/'.$newname;
move_uploaded_file( $_FILES['file']['tmp_name'], $target);;
$filename=$newname;
if($ext=='jpg'||$ext=='jpeg')
{
$im = imagecreatefromjpeg('uploads/'.$filename);
}
else if ($ext=='gif')
{
$im = imagecreatefromgif('uploads/'.$filename);
}
else if ($ext=='png')
{
$im = imagecreatefrompng('uploads/'.$filename);
}
$ox = imagesx($im);
$oy = imagesy($im);
$nm = imagecreatetruecolor(245, 184);
imagealphablending( $nm, FALSE );
imagesavealpha( $nm, TRUE );
imagecopyresized($nm, $im, 0,0,0,0,245,184,$ox,$oy);
imagejpeg($nm, 'uploads/' . $filename);
答案 0 :(得分:1)
答案 1 :(得分:0)
避免使用dropzone resizeWidth方法。 调整后端图像的大小。