【问题标题】:Inserting text in image not working in PHP在图像中插入文本在 PHP 中不起作用
【发布时间】:2019-08-27 15:22:29
【问题描述】:

我的函数返回错误信息:

Call to undefined function imagettftext()

我已经尝试了所有方法,但无法启用(--with-freetype-dir=DIR)

    $black = imagecolorallocate($text_im, 0, 0, 0);
    imagefilledrectangle($text_im, 0, 0, 399, 29, $white);
    $text = 'testing shop ,9876543214';
    // Replace path by your own font path
    $font = 'arial.ttf';
    imagettftext($text_im, 20, 0, 10, 20, $black, $font, $text);
    imagepng($text_im);```

【问题讨论】:

  • 是否启用了gd 扩展?这可以通过搜索调用phpinfo() 并检查页面是否包含GD 来检查
  • 是的,它已启用
  • 您是否指向您计算机上的 freetype-dir? ` --with-freetype-dir=/usr/local/lib/freetype-2.1.9/`
  • 不知道如何在 mac 中做到这一点
  • 我添加了一个指南作为答案

标签: php php-7 imagettftext


【解决方案1】:

GD 和 Freetype 都必须安装,Freetype 可以使用以下方式安装:

brew install freetype

安装完成后执行以下命令获取路径:

echo "/usr/local/Cellar/freetype/$(ls /usr/local/Cellar/freetype)/lib"

然后在标志中使用该路径:

--with-freetype-dir=/usr/local/Cellar/freetype/2.10.1/lib

第二种选择是按照以下步骤从头开始编译 PHP:

  1. 下载php:https://www.php.net/downloads.php
  2. 解压压缩包
  3. 打开终端并导航到文件夹
  4. 运行:
./configure \
  --prefix=/usr/local/bin/php \
  --with-apxs2=/usr/local/apache/bin/apxs \
  --enable-mbstring \
  --with-curl \
  --with-openssl \
  --with-xmlrpc \
  --enable-soap \
  --enable-zip \
  --with-gd \
  --with-jpeg-dir \
  --with-png-dir \
  --with-mysqli \
  --with-pgsql \
  --enable-embedded-mysqli \
  --with-freetype-dir \
  --with-ldap \
  --enable-intl \
  --with-xsl \
  --with-zlib
  1. 然后运行:
make
  1. 并安装它:
make install

【讨论】:

  • 检查我会告诉你回复。
  • 如何采取 3 步。
  • 你是如何在你的mac上安装php的?你用自制的吗? @GauravGupta
  • 您使用的是 xampp 还是 mamp? @GauravGupta
  • 我已经安装了 php apache mysql 个人
猜你喜欢
  • 2013-01-18
  • 1970-01-01
  • 2010-11-28
  • 2019-02-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-05
  • 1970-01-01
相关资源
最近更新 更多