簡體   English   中英

透明疊加層創建PNG

[英]Transparent Overlay Creating PNG

我具有以下功能,並且已經達到所需的大小,現在我要添加背景圖像,然后希望在所有覆蓋文本上僅添加具有透明背景的文本覆蓋,但是imagefilledrectangle應用變量$white可以預期,我正在嘗試查看是否有某種方法告訴該函數透明而不是接受一種顏色,在這種情況下為白色,PHP文檔說該顏色是imagefilledrectangle的必需參數,任何建議都imagefilledrectangle贊賞。

背景圖像是本地圖像:

define("BACKGROUND_FILE", "background.png");

功能:

public function generateImage()
{
    if (file_exists(BACKGROUND_FILE)) {     
        $im = @imagecreatefrompng(BACKGROUND_FILE);

        if($im) {
            $white = imagecolorallocate($im, 255, 255, 255);
            $black = imagecolorallocate($im, 115, 150, 195);

            imagefilledrectangle($im, 0, 0, 399, 29, $white);

            $text = 'Test';
            $font = 'arial_narrow_7.ttf';

            imagettftext($im, 20, 0, 10, 20, $black, $font, $text);

            imagepng($im);
            imagedestroy($im);
        } else {
            echo 'Error';
        }
    }
}

我嘗試添加imagecolortransparent($im, $white); imagefilledrectangle之前,但沒有任何區別。

弄清楚了,函數中不需要有imagefilledrectangle線,下面給出了透明的覆蓋文本元素,因為現在不應用填充。

public function generateImage()
{
    if (file_exists(BACKGROUND_FILE)) {     
        $im = @imagecreatefrompng(BACKGROUND_FILE);

        if($im) {
            $black = imagecolorallocate($im, 115, 150, 195);

            $text = 'Test';
            $font = 'arial_narrow_7.ttf';

            imagettftext($im, 20, 0, 10, 20, $black, $font, $text);

            imagepng($im);
            imagedestroy($im);
        } else {
            echo 'Error';
        }
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM