简体   繁体   English

如何在Php Gd中更改字体和字体大小?

[英]How to Change Font And Font Size In Php Gd?

I will change 5 to 50 100 saved but result not changing anything everytime showing small text only and how to change font also and $string = $user['name'] ; 我将保存5到50100,但是每次仅显示小文本以及如何更改字体以及$string = $user['name']都不会更改任何内容; this line printing full name we want only first name of fb graph api please help. 这行打印全名,我们只希望使用fb graph api的名字来帮助。

My code as below: 我的代码如下:

$barcode1 = imagecreatefrompng($image_bg);
            imagecopy($fullimage, $im1, 35, 74, 0, 0, 365, 317);
            imagecopyresampled($fullimage, $barcode1, 0, 0, 0, 0, imagesx($fullimage), imagesy($fullimage), imagesx($barcode1), imagesy($barcode1));

$color = imagecolorallocate($fullimage, 0, 0, 0);
$string = $user['name'];
$fontSize = 5;
$x = 95;
$y = 344;
$font = 'arial.ttf';

imagestring($fullimage, $fontSize, $x, $y, $string, $color);

$imagename = date("Ymd") . uniqid() . uniqid() . uniqid() . '.jpg';
imagejpeg($fullimage, 'Apps/If_You_Produce/123321/' . $imagename, 100);

$values['user_id'] = $userid;
$values['image_name'] = $imagename;
$db->insert($db_table_name, $values);

You can not use 10,50,100 - http://php.net/manual/en/function.imagestring.php 您不能使用10,50,100- http: //php.net/manual/en/function.imagestring.php

Only 1-5 (by default) 仅1-5(默认情况下)

UPDATE 更新

To be able fully control the font size you might want to use http://php.net/manual/en/function.imagettftext.php 为了完全控制字体大小,您可能需要使用http://php.net/manual/en/function.imagettftext.php

Example (from the same site): 示例(来自同一站点):

<?php
// Set the content-type
header('Content-Type: image/png');

// Create the image
$im = imagecreatetruecolor(400, 30);

// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);

// The text to draw
$text = 'Testing...';
// Replace path by your own font path
$font = 'arial.ttf';

// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);

// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);

// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM