doutao1171 2018-10-19 04:44
浏览 67

使用PHP GD向图像添加文本

I am trying to add a hindi text to an image using PHP GD and the text is being converted to squares, I think this is happening, php gd is not supporting hindi text.

Please tell me how to solve this issue or is there any other way to add hindi text to an Image.

This is the code I am using:

  //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);

Result I am Getting :

enter image description here

  • 写回答

1条回答 默认 最新

  • dream989898 2018-10-19 06:08
    关注

    For Hindi Letters you need to use utf8_encode() to encode hindi letters to PHP context.

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

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题