imageloadfont()
kullanılır: İşte benim kod. Arial veya başka bir TrueType yazı tipini (.ttf) veya OpenType yazı tiplerini (.otf) kullanmak istiyorsanız (GD lib'deki ikincisi için destek buggy'tir), ihtiyacınız olan şey imagettftext()
'dur. imagettftext()
'u kullanmadan ve resminize yazı yazmadan önce, ilk önce uygun olup olmayacağını bilmeniz gerekir. Bunu bilmek için sadece imagettfbbox()
numaralı telefonu aramanız ve yazı tipi boyutunu, metnin açısını (yatay metin için 0), .ttf veya .otf yazı tipi dosyanızın yolunu ve metin dizesini iletmeniz yeterlidir. Metnin sınırlayıcı kutusunu oluşturan dört noktadan oluşan 8 elemanlı dizi (özellikler için PHP kılavuzunu kontrol edin). Daha sonra bu dizi elemanlarına başvurabilir ve belirli bir metin dizesinin genişliğini ve yüksekliğini öğrenmek için hesaplamalar yapabilirsiniz. Bu değerleri, metnin bütünüyle görüntülenmesine izin verecek belirli bir genişlik ve yüksekliğe sahip bir görüntü oluşturmak için kullanabilirsiniz.
Burada seni almak için yapmaya çalıştıkları şey başarması bundan basit bir script başladı:
<?php # Script 1
/*
* This page creates a simple image.
* The image makes use of a TrueType font.
*/
// Establish image factors:
$text = 'Sample text';
$font_size = 12; // Font size is in pixels.
$font_file = 'Arial.ttf'; // This is the path to your font file.
// Retrieve bounding box:
$type_space = imagettfbbox($font_size, 0, $font_file, $text);
// Determine image width and height, 10 pixels are added for 5 pixels padding:
$image_width = abs($type_space[4] - $type_space[0]) + 10;
$image_height = abs($type_space[5] - $type_space[1]) + 10;
// Create image:
$image = imagecreatetruecolor($image_width, $image_height);
// Allocate text and background colors (RGB format):
$text_color = imagecolorallocate($image, 255, 255, 255);
$bg_color = imagecolorallocate($image, 0, 0, 0);
// Fill image:
imagefill($image, 0, 0, $bg_color);
// Fix starting x and y coordinates for the text:
$x = 5; // Padding of 5 pixels.
$y = $image_height - 5; // So that the text is vertically centered.
// Add TrueType text to image:
imagettftext($image, $font_size, 0, $x, $y, $text_color, $font_file, $text);
// Generate and send image to browser:
header('Content-type: image/png');
imagepng($image);
// Destroy image in memory to free-up resources:
imagedestroy($image);
?>
Değişiklik değerleri buna göre ihtiyaçlarına uygun. PHP kılavuzunu okumayı unutma. GD2 ile
bir atın [imagettfbbox] 'a bakın (http://www.php.net/manual/en/function.imagettfbbox.php) ve [imagettftext] (http://php.net/manual/en/function.imagettftext.php). – Vatev