我正在使用下面的代码来调整图像的大小。上传透明图像(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);
尝试使用
imagecolortransparent
在您的代码中。
http://www.php.net/manual/en/function.imagecolortransparent.php
避免使用dropzone resizeWidth方法。在后端调整图像大小。