无法更改GD imagestring()的字体大小

Pow*_*Pow 16 php image

我正在尝试按照此示例生成带有动态文本的图像.

我想改变字体的大小,我把它放到100而不是4,但它仍然像以前一样.

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

这是一个小小的例子 :(

这是我的示例代码 -

       $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);
Run Code Online (Sandbox Code Playgroud)

谢谢

加上以后

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

       $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);
Run Code Online (Sandbox Code Playgroud)

Zol*_*oth 17

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

仅1-5(默认情况下)

UPDATE

为了能够完全控制您可能想要使用的字体大小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);
?>
Run Code Online (Sandbox Code Playgroud)

  • 那太小了:( (2认同)