【问题标题】:How to create images for dynamic text using PHP?如何使用 PHP 为动态文本创建图像?
【发布时间】:2017-11-18 23:23:24
【问题描述】:

我想为我的动态文本创建图像。
我的问题是我正在从某个特定目录读取文件夹名称。
所以文件夹名称将是什么,但客户希望该文件夹名称应仅作为图像出现。
所以我想我会在任何唯一名称上放置一张与文件夹同名的图像。
但是如果客户创建一个新文件夹,他们不想创建新图像。 那么我该如何使用 PHP 做到这一点呢?
我需要为图像使用一些特定的背景颜色,并且还想为图像中的文本使用一些特定的字体。

【问题讨论】:

    标签: php image image-processing


    【解决方案1】:

    请参阅示例部分中的imagefttext()

    【讨论】:

      【解决方案2】:

      来自 php.net: http://pl2.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
        • 2023-03-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-09-12
        • 2012-07-30
        • 1970-01-01
        相关资源
        最近更新 更多