[英]PHP - Black background after resizing transparent png and gif
我正在使用以下代碼調整圖像大小。 上傳透明圖像 (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);
避免使用 dropzone resizeWidth 方法。 在后端調整圖像大小。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.