标签: imagettftext

PHP imagettftext 总是绘制黑色

基本上,当我绘制文本时,它最终会变成黑色,如下所示: https: //i.stack.imgur.com/z675F.png 而不是我在 PHP 和函数中分配的颜色。代码:

    $finalImage = imagecreatefrompng($imageFile);
    $logo = imagecreatefrompng($logoImage);
    imagecopy($finalImage, $logo, $logoPosition['x'], $logoPosition['y'], 0, 0, imagesx($logo), imagesy($logo));
    $font = "arial.ttf";
    $fontSize = 10;
    $yOffSet = 15;
    $white = imagecolorallocate($finalImage, 255, 255, 255);
    foreach($pixelArray as $key => $x) {
        foreach($valueArray[$key] as $valueText) {

            imagettftext($finalImage, $fontSize, 0, $x, $yOffSet, $white, $font, $valueText);
            $yOffSet += 15;
        }
        $yOffSet = 15;
    }
    if($miscText != null) {
        foreach($miscText as $key => $text) {
            imagettftext($finalImage, $fontSize, 0, $text['x'], $text['y'], $white, $font, $text['text']);    
        } …
Run Code Online (Sandbox Code Playgroud)

php gd imagettftext

4
推荐指数
1
解决办法
3699
查看次数

支持php imagettftext的所有utf-8字符的字体

我在php中使用imagettftext来生成图像.是否有支持所有utf-8字符的真实字体?

php utf-8 truetype imagettftext

4
推荐指数
2
解决办法
8219
查看次数

PHP的imagettftext在透明背景上创建黑色边缘

我有这个代码:

$im = imagecreatetruecolor(70, 25);

$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);

imagecolortransparent($im, imagecolorallocate($im, 0,0,0));

$font = 'font.ttf';

imagettftext($im, 20, 0, 3, 22, $white, $font, $randomnr);

header("Expires: Wed, 1 Jan 1997 00:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

header ("Content-type: image/png");
imagepng($im);
imagedestroy($im);
Run Code Online (Sandbox Code Playgroud)

就像我在标题中所说的,它会在文本周围创建一些黑色边缘.我也试过imagealphablending/ imagesavealpha和我有相同的结果(我在透明背景上使用白色文字,以便你可以看到我在说什么):

黑边

更新:解决方案是:

$im = imagecreatetruecolor(70, …
Run Code Online (Sandbox Code Playgroud)

php imagettftext

4
推荐指数
2
解决办法
4712
查看次数

如何在多行(段落中)中写入文本?

当我使用这段代码时,我可以用文字制作图像,但是在一行中,

function writetext($image_path,$imgdestpath,$x,$y,$angle,$text,$font,$fontsize) {
      $image=imagecreatefromjpeg("$image_path");
      $height = imageSY($image);
      $width = imageSX($image);
      $color = imagecolorallocate($image,0,0,0);
      $textwidth = $width;
      imageTTFtext($image,$fontsize,$angle,$x,$y,$color,$font, $text );
      ImageJPEG($image,$imgdestpath);
}
Run Code Online (Sandbox Code Playgroud)

请告诉我如何在多行段落中制作此图像?

php imagettftext

4
推荐指数
1
解决办法
3637
查看次数

PHP imagettftext() 居中文本

我想使用以下方法将添加到图像中的文本居中:

imagettftext($image, 85, 0, 250, 350, $color, $font, $txt );
Run Code Online (Sandbox Code Playgroud)

我尝试过这样的事情:

$fontwidth1 = imagefontwidth($font);
$center1 = (imagesx($image)/2) - ($fontwidth1*(strlen($txt)/2));
Run Code Online (Sandbox Code Playgroud)

但不幸的是它不起作用。imagefontwidth($font) 部分不起作用:(

有人以前遇到过这个问题并知道解决方案/替代方法吗?

php imagettftext

3
推荐指数
1
解决办法
1万
查看次数

imagettftext中的欧元(€)

我怎样才能创建一个€符号imagettftext()?我正在使用包含欧元符号的'Lucida Grande'字体. €也行不通.

php imagettftext

2
推荐指数
1
解决办法
766
查看次数

如何控制使用`imagettftext()`生成的文本的文本对齐?

使用imagettftextPHP GD库中的函数,只能绘制左对齐到图像上的文本.至少看起来似乎,也许我错过了一些东西.

如何控制绘制到图像上的文本的对齐方式?即左/中/右(/对齐 - 没必要,但有用)

我应该提一下,当绘制的文本包含多行时,对齐是可见的(例如"bla bla bla/n和另一行bla.").

php gd imagettftext

2
推荐指数
2
解决办法
9126
查看次数

生成验证码图像PHP

我想使用PHP imagettftext生成Captcha Image.以下是我的代码.它给出了一个空图像.我想解决这个问题.

我已经测试了代码,但无法找到为什么图像不是bieng显示,虽然我的随机文本被传递给验证码图像生成的功能.

<?php

    function generateRandomString($length = 10) {
        $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
        $randomString = '';
        for ($i = 0; $i < $length; $i++) {
            $randomString .= $characters[rand(0, strlen($characters) - 1)];
        }
        return $randomString;
    }

    function generateCaptchaImage($text = 'good'){
        echo $text;
        echo 'OK';
        // Set the content-type
        header('Content-Type: image/png');

        $width = 200;
        $height = 30;
        $font = 'ThisisKeSha.ttf';

        // Create the image
        $im = imagecreatetruecolor($width, $height);

        //ADD NOISE - DRAW background squares
        $square_count = 6;
        for ($i = 0; $i …
Run Code Online (Sandbox Code Playgroud)

php captcha text image imagettftext

2
推荐指数
1
解决办法
8953
查看次数

移动上传的文件php无效

我想移动一个使用imagettftext创建并保存为png的文件.正如您所看到的,在下面的代码中,我使用了move_uploaded_file但无济于事.请帮忙.

TQ

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



// Create the image from created image
//$im = imagecreatetruecolor(180, 180);
$im = @imagecreatefromjpeg('poloroid.jpg');

// 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 = 'John...';
$fbid = $_POST["id"]; 
$text = $_POST["want"];
$fb_email =$_POST["email"];
$fb_name=$_POST["name"];

$uploads_dir = '/uploaded_files';
// Replace path by your own font path
$font = …
Run Code Online (Sandbox Code Playgroud)

php upload imagettftext

1
推荐指数
1
解决办法
872
查看次数

标签 统计

imagettftext ×9

php ×9

gd ×2

captcha ×1

image ×1

text ×1

truetype ×1

upload ×1

utf-8 ×1