![](/img/trans.png)
[英]Black background on creating a image from imagegrabscreen() with php
[英]Why is this creating a black image?
在圖像文件夾中,我有一個notfound.php文件,
<?php
header('Content-type: image/png');
$im = imagecreatefrompng('simnotfound.png');
imagepng($im);
imagedestroy($im);
?>
圖像是256 x256。notfound.php頁面顯示黑色256 x 256平方。 圖像並非全黑。 它只是中間透明背景上的一些黑色文字。
解決方法是
<?php
header('Content-type: image/png');
$im = imagecreatefrompng('simnotfound.png');
imagealphablending($im, true); // setting alpha blending on
imagesavealpha($im, true); // save alphablending setting (important)
imagepng($im);
imagedestroy($im);
?>
再創建一次具有白色背景的圖像文件,以檢查是否正確讀取(如果是)-問題是您的透明背景
也嘗試使用其他文件來消除讀取此特定文件的問題
bool imagesavealpha ( resource $image , bool $saveflag )
imagesavealpha —設置該標志以在保存PNG圖像時保存完整的Alpha通道信息(與單色透明相反)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.