【问题标题】:How to Change Font And Font Size In Php Gd?如何更改 Php Gd 中的字体和字体大小?
【发布时间】:2017-05-09 20:25:34
【问题描述】:

我会将 5 更改为 50 100 已保存但结果不会更改任何内容,每次仅显示小文本以及如何更改字体以及 $string = $user['name'];此行打印全名,我们只需要 fb graph api 的名字,请帮忙。

我的代码如下:

$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);

【问题讨论】:

  • 你应该考虑编辑你的帖子主要是为了格式化。

标签: php facebook-graph-api facebook-apps php-gd


【解决方案1】:

你不能使用 10,50,100 - http://php.net/manual/en/function.imagestring.php

只有 1-5 个(默认)

更新

为了能够完全控制您可能想要使用的字体大小http://php.net/manual/en/function.imagettftext.php

示例(来自同一站点):

<?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);
?>

【讨论】:

  • 你有没有遇到任何问题,上面的例子?
猜你喜欢
  • 1970-01-01
  • 2011-06-14
  • 1970-01-01
  • 1970-01-01
  • 2011-06-25
  • 1970-01-01
  • 1970-01-01
  • 2015-10-22
  • 2015-01-10
相关资源
最近更新 更多