-2
如何調整png和gif圖像的大小並使用php存儲透明背景?如何在PHP中將圖像的背景顏色從黑色更改爲透明?
這是我的代碼
你將圖像尺寸調整到200×200像素,並爬升到PIE目錄。這是一個很好的工作。但與png或gif圖像(透明bg)一起使用時。它會將bg更改爲黑色。調整圖像大小後,如何使scrib透明bg?
原文:
複製:
include 'compressImage.php';
<?php
$widthArray = array(200);
foreach($widthArray as $newwidth)
{
compressImage($ext,$tmp,$path,$userID.$actual_image_name,$newwidth);
}
?>
compressImage.php:
<?php
//Compress Image
function compressImage($ext,$uploadedfile,$path,$actual_image_name,$newwidth)
{
if($ext=="jpg" || $ext=="jpeg")
{
$src = imagecreatefromjpeg($uploadedfile);
}
else if($ext=="png")
{
$src = imagecreatefrompng($uploadedfile);
}
else if($ext=="gif")
{
$src = imagecreatefromgif($uploadedfile);
}
else
{
$src = imagecreatefrombmp($uploadedfile);
}
list($width,$height)=getimagesize($uploadedfile);
$newheight=($height/$width)*$newwidth;
$tmp=imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
$filename = $path.$newwidth.'_'.$actual_image_name;
imagejpeg($tmp,$filename,100);
imagedestroy($tmp);
return $filename;
}
?>
https://es.stackoverflow.com/q/94015/29516 – Shareiv