我有一个图像调整大小功能,正在调整image/jpg/gif/jpeg/png
的大小。
一切都很好,除了透明的大拇指backgorund之外,如果图像透明,则可以创建黑色的背景大拇指。
我尝试了PHP.NET中的一些示例,但仍然使山姆黑了。
我最接近的答案是This one,但这对我再次给出结果黑色没有帮助。
这是我的调整大小功能:
function createThumbnail($sourcePath,$targetPath,$file_type,$thumbWidth,$thumbHeight){
switch (strtoupper($file_type)):
case 'jpg':
$source = imagecreatefromjpeg($sourcePath);
break;
case 'JPG':
$source = imagecreatefromjpeg($sourcePath);
break;
case 'png':
$source = imagecreatefrompng($sourcePath);
break;
case 'PNG':
$source = imagecreatefrompng($sourcePath);
break;
case 'gif':
$source = imagecreatefromgif($sourcePath);
break;
case 'GIF':
$source = imagecreatefromgif($sourcePath);
break;
default:
echo "Invalid File Type";
endswitch;
$width = imagesx($source);
$height = imagesy($source);
$tnumbImage = imagecreatetruecolor($thumbWidth,$thumbHeight);
imagecopyresampled($tnumbImage,$source,$thumbHeight,$width,$height);
if(imagegif($tnumbImage,80)) {
imagedestroy($tnumbImage);
imagedestroy($source);
return TRUE;
}if(imagepng($tnumbImage,80)) {
imagedestroy($tnumbImage);
imagedestroy($source);
return TRUE;
}if(imagejpeg($tnumbImage,80)) {
imagedestroy($tnumbImage);
imagedestroy($source);
return TRUE;
} else {
return FALSE;
}
}
usaqe我正在通过另一个函数来校准它:
createThumbnail($temp_path,$small_thumbnail,$fileType,150,93);