Я использую библиотеку PHP GD, чтобы пользователи могли генерировать свое имя поверх фонового изображения, которое я предоставляю. Текущая проблема заключается в том, что буквы в выводимом PNG непрозрачны — как вы можете видеть ниже, они перекрывают друг друга.
Текст: Роджер Аякс
Фоновая картинка:
Результат:
Возможно ли это из-за шрифта TTF? Я пробовал следующие шрифты с тем же результатом:
- HomemadeApple.ttf
- IndieFlower.ttf
- DancingScript.ttf
- KaushanScript Regular.ttf
- PermanentMarker.ttf
Вот полный источник моей функции:
$signature_text = "Roger Ajax";
$font_name = "Homemade Apple";
// Lowercase all letters then capitalize First Lettter of each word
$signature_text = strtolower($signature_text);
$signature_text = ucwords($signature_text);
// Font & Text Settings
$font_size = 32;
$font = "/var/gosigner/fonts/HomemadeApple.ttf";
$desired_width = strlen($signature_text) * 34;
$start_position = 32;
// Background Image
$originalImage = $this->config->item('app_root') . "img/signature_field_blank.png";
// Verify BG Image can be found
if(!file_exists($originalImage)) {
$this->shared->throw_error("Signature template file could not be found");
}
$im = imagecreatefrompng($originalImage); // Get original
imagealphablending($im, false); // Save Transparency
imagesavealpha($im, true); // Save Transparencyc
$img_resized = imagecreatetruecolor($desired_width, 72); // Create new PNG
imagealphablending($img_resized, false); // Save Transparency
imagesavealpha($img_resized, true);
$trans_colour = imagecolorallocatealpha($img_resized, 0, 0, 0, 127);
imagefill($img_resized, 0, 0, $trans_colour);
$x = imagesx($im); // Original X
$y = imagesy($im); // Original Y
imagecopyresampled($img_resized, $im, 0, 0, 0, 0, 214, 72, $x, $y);
$black = imagecolorallocate($im, 0, 0, 0);
imagettftext($img_resized, $font_size, 0, $start_position, 45, $black, $font, $signature_text);
header('Content-Type: image/png');
imagepng($img_resized);
imagedestroy($im);
imagedestroy($img_resized);