无法更改GD imagestring()的字体大小 [英] Can't change font size for GD imagestring()

查看:132
本文介绍了无法更改GD imagestring()的字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试关注此示例生成带有动态文本的图像。

I'm trying to follow this example to generate an image with dynamic text.

我想改变字体的大小,我甚至把它放在100而不是4,但它仍然和以前一样。

I wanted to change the size of the font, I put even 100 instead of 4, but it still appears same as before.

我不擅长PHP。任何形式的帮助将不胜感激。

I'm not very good at PHP. Any sort of help would be appreciated.

这里是一个例子出现的小小:(

Here's an example how small it appears :(

这是我的示例代码 -

Here's my example code -

       $font = 'arial.ttf'; //FONT SIZE

       $width = imagefontwidth($font) * strlen($string) ;
       $height = imagefontheight($font) ;
       $im = imagecreatefrompng($imageO);

       $x = imagesx($im) / 2;   //PLACEMENT CENTERISH – X
       $y = imagesy($im) / 2;   //PLACEMENT CENTERISH – Y

      // $backgroundColor = imagecolorallocate ($im, 255, 255, 255);

       $transparency = 25;
       imagesavealpha($im, true);
       $background = imagecolorallocatealpha($im, background_r, background_g, background_b, $transparency);

       $textColor = imagecolorallocate ($im, 0,0,0);
       imagestring ($im, $font, $x, $y, $string, $textColor);
       imagepng($im,$imageN[$k]);
       $w = imagesx($im);
       $h = imagesy($im);

谢谢

现在好了,这就是我所做的,但结果是,在标注框中看不到任何文字。

Ok now here it is what I have done but as a result, no text is visible in the callout box.

       $font = 'arial.ttf'; //YOUR FONT SIZE

       $im = imagecreatefrompng($imageO);
       $string = "My Text";
       $imageN ="NewImage.png";

       $transparency = 25;
       imagesavealpha($im, true);
       $background = imagecolorallocatealpha($im, background_r, background_g, background_b, $transparency);

       $textColor = imagecolorallocate ($im, 0,0,0);
       //imagestring ($im, 5, $x, $y, $string, $textColor);
       imagettftext($im, 36, 0, 10, 20, $textColor, $font, $string);
       imagepng($im,$imageN);


推荐答案

你不能把100 - http://php.net/manual/en/function.imagestring.php

You can't put 100 - http://php.net/manual/en/function.imagestring.php

仅限1-5(默认情况下)

Only 1-5 (by default)

更新

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

To be able fully control the font size you might want to use 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);
?>

这篇关于无法更改GD imagestring()的字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆