0

透明な画像の生成に関する多くの記事を読みましたが、それでも透明性に問題があります。まず第一に、ここに私のコードがあります:

<?php
$text = 'I feel dirty with those borders';
$color = array( 255, 128, 0);
$font = 'arial.ttf';
$size = 44;

// Create the image
$testImg = imagecreatetruecolor(20, 20);
$testCol = imagecolorallocate($testImg, $color[0], $color[1], $color[2]);
$rect = imagettftext($testImg, $size, 0, 0, 0, $testCol, $font, $text);
$width = $rect[4] - $rect[0] + 2;
$height = $rect[1] - $rect[5];
$yOffset = -$rect[5];

imagedestroy($testImg);

$img = imagecreatetruecolor( $width, $height);
imageantialias ( $img, true);
$black = imagecolorallocate($img, 0, 0, 0);
imagecolortransparent($img, $black);
$col = imagecolorallocate($img, $color[0], $color[1], $color[2]);
$rect = imagettftext($img, $size, 0, -1, $yOffset, $col, $font, $text);
imagepng($img, "test.png");
imagedestroy($img);

?>
<html>
<body bgcolor="ffFFa0">
<img src="test.png" />
</body>
</html>

このコードを使用して画像を生成すると、文字の色が完全に不透明または完全に透明ではないテキストの周囲に黒い境界線が表示されます。その理由は、100%黒のピクセルだけが透明になっているからだと思います。しかし、他にどのような方法がありますか?また、アルファブレンディングを使用しようとしましたが、成功しませんでした。

誰かが私に良い例へのヒントやリンクを教えてもらえますか?

前もって感謝します

パラスカス

4

0 に答える 0