2
我正在嘗試將一段文本更改爲圖像。我無法弄清楚我的代碼有什麼問題,以及如何使它透明。這是我到目前爲止:PHP:將文本更改爲具有透明度的PNG圖像的功能
<?PHP
function fsrep_imageaddress($address, $listingid) {
$font_size = 4;
$width = imagefontwidth($font_size)*strlen($address);
$height = imagefontheight($font_size);
$img = imagecreate($width,$height);
$bg = imagecolorallocate($img, 25, 25, 25);
$color = imagecolorallocate($img, 255, 255, 255);
$len = strlen($address);
$ypos = 0;
for($i=0;$i<$len;$i++){
$xpos = $i * imagefontwidth($font_size);
imagechar($img, $font_size, $xpos, $ypos, $address, $color);
$address = substr($address, 1);
}
imagepng($img, ABSPATH.'wp-content/uploads/fsrep/houses/address-'.$listingid.'.png',100);
imagedestroy($img);
}
fsrep_imageaddress(Just Testing, 12)
?>
什麼是目前你的腳本做錯了?你需要做的第一件事就是把'Just Testing'放在引號中,因爲它是一個字符串而不是常量 –