【问题标题】:Adding text to image with PHP GD使用 PHP GD 向图像添加文本
【发布时间】:2019-03-23 23:17:54
【问题描述】:

我正在尝试使用 PHP GD 将印地文文本添加到图像中,并且文本正在转换为正方形,我认为这正在发生,php gd 不支持印地文文本。

请告诉我如何解决这个问题,或者有没有其他方法可以将印地语文本添加到图像中。

这是我正在使用的代码:

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

  // Create Image From Existing File
  $jpg_image = imagecreatefromjpeg('temp/mango.jpg');

  // Allocate A Color For The Text
  $white = imagecolorallocate($jpg_image, 255, 255, 255);
  $black = imagecolorallocate($jpg_image, 0,0,0);

  $font = dirname(__FILE__) . '/font/opensans.ttf';

  // Set Text to Be Printed On Image

  // Print Text On Image
  imagettftext($jpg_image, 25, 0, 75, 300, $white, $font, "आम फलो का राजा है। ");




  // Send Image to Browser
  imagejpeg($jpg_image);

  // Clear Memory
  imagedestroy($jpg_image);

我得到的结果:

【问题讨论】:

标签: javascript php


【解决方案1】:

对于印地语字母,您需要使用 utf8_encode() 将印地语字母编码为 PHP 上下文。

imagettftext($jpg_image, 25, 0, 75, 300, $white, $font, utf8_encode("आम फलो का राजा है। "));

【讨论】:

    猜你喜欢
    • 2012-10-27
    • 1970-01-01
    • 2012-05-22
    • 1970-01-01
    • 2014-05-20
    • 1970-01-01
    • 2012-05-27
    相关资源
    最近更新 更多