imagettftext给出奇怪的结果
问题描述:
试图在php中已经存在的图像上画一些文字,但得到奇怪的结果。imagettftext给出奇怪的结果
下面是代码:
<?php
$font = "files/fonts/open_sans/OpenSans-Regular-webfont.ttf";
$image = imagecreatefrompng('images/icons/marker_icon.png');
$white = ImageColorAllocate($image, 255,255,255);
imagettftext($image, 1, 1, 1, 1, $white, $font, $_GET['count']);
header("content-type: image/png");
imagepng($image);
imagedestroy($image);
?>
第一次在图像上绘画,所以我不知道我做错了什么。
答
想通了。由于有很多的透明度在我的形象,我必须设置imageAlphaBlending
到true
:
<?php
$font = "files/fonts/open_sans/OpenSans-Regular-webfont.ttf";
$image = imagecreatefrompng('images/icons/marker_icon.png');
$white = ImageColorAllocate($image, 255,255,255);
imageAlphaBlending($image, true);
imageSaveAlpha($image, true);
imagettftext($image, 15, 0, 10, 35, $white, $font, $_GET['count']);
header("content-type: image/png");
imagepng($image);
imagedestroy($image);
?>
答
这个问题是你的形象,我不知道如何或为什么,但它被搞砸了。我在一个照片编辑器中打开它,并用一个不同的名称重新命名为PNG,它工作。此外,您的文本将不会显示,因为您的字体大小设置为1,它从xy 1,1开始。它应该反映如下:
<?php
$font = "files/fonts/open_sans/OpenSans-Regular-webfont.ttf";
$image = imagecreatefrompng('images/icons/marker_icon.png');
$white = ImageColorAllocate($image, 255,255,255);
imagettftext($image, 15, 0, 10, 35, $white, $font, $_GET['count']);
header("content-type: image/png");
imagepng($image);
imagedestroy($image);
?>
你用什么照片编辑器?我使用的是Photoshop,我试过这个,但它没有工作。 –
油漆哈哈。也许它与photoshop使用的颜色有关。 – spencdev