无法在php 8.1.5 Docker容器中启用gd的Freetype

qncylg1j  于 2022-11-03  发布在  Docker
关注(0)|答案(2)|浏览(268)

问题:Call to undefined function imagettfbboxfunction_exists('imagettfbbox')的输出是false
我已经看到了这么多的Dockerfile现在,似乎并不那么困难,以gd启用Freetype。然而,虽然我的Dockerfile构建没有错误,当我看phpinfo时,Freetype没有启用。
我错过了什么?

GD Support          enabled
GD Version          bundled (2.1.0 compatible)
GIF Read Support    enabled
GIF Create Support  enabled
PNG Support         enabled
libPNG Version      1.6.37
WBMP Support        enabled
XBM Support         enabled
BMP Support         enabled
TGA Read Support    enabled

这是我的Dockerfile

FROM php:8.1.5-fpm-alpine3.15

ENV PHP_OPCACHE_VALIDATE_TIMESTAMPS="0" \
    PHP_OPCACHE_MAX_ACCELERATED_FILES="20000" \
    PHP_OPCACHE_MEMORY_CONSUMPTION="256" \
    PHP_OPCACHE_MAX_WASTED_PERCENTAGE="10"

RUN apk add bash curl zip libzip-dev libxpm libxpm-dev libpng libpng-dev libwebp libwebp-dev libjpeg-turbo libjpeg-turbo-dev freetype freetype-dev imagemagick imagemagick-dev && rm /var/cache/apk/*
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer

RUN docker-php-ext-install pdo_mysql

RUN apk add $PHPIZE_DEPS
RUN pecl install redis
RUN docker-php-ext-configure zip 
RUN docker-php-ext-configure gd --enable-gd --with-webp --with-jpeg --with-xpm --with-freetype 
RUN docker-php-ext-install zip opcache
RUN docker-php-ext-install gd 
RUN docker-php-ext-enable redis 

RUN apk del --purge autoconf g++ make

WORKDIR /var/www

COPY ./dockerfiles/php/php.ini /usr/local/etc/php/php.ini
COPY ./dockerfiles/php/php-fpm-pool.conf /usr/local/etc/php-fpm.d
COPY ./dockerfiles/php/opcache.ini /usr/local/etc/php/conf.d/opcache.ini

COPY ./app/ /var/www

RUN PATH=$PATH:/var/www/bin:bin

RUN composer install

CMD ["php-fpm", "-F"]

以及引用的配置:
第一个

rdrgkggo

rdrgkggo1#

也许这样可以解决它:

RUN apk add --no-cache freetype-dev libjpeg-turbo-dev libpng-dev libzip-dev zlib-dev
RUN docker-php-ext-configure gd --enable-gd --with-freetype --with-jpeg
RUN docker-php-ext-install gd
yzckvree

yzckvree2#

我能够使用这个Dockerfile构建Freetype支持

FROM php:8.1-fpm

RUN apt-get update \
    && apt-get install -y zlib1g-dev libpq-dev git libicu-dev libxml2-dev libcurl4-openssl-dev \
    pkg-config libssl-dev libzip-dev zlib1g-dev \
    libfreetype6-dev libjpeg62-turbo-dev libpng-dev

RUN docker-php-ext-configure gd --enable-gd --prefix=/usr --with-jpeg --with-freetype \
    && docker-php-ext-install -j$(nproc) gd

RUN php -r 'var_dump(gd_info());'

由于PHP 7.4... -dir选项(如--with-freetype-dir,--with-jpeg-dir等)被删除,所以应该使用--prefix=/usr
gd_info()输出

["GD Version"]=>
  string(26) "bundled (2.1.0 compatible)"
  ["FreeType Support"]=>
  bool(true)
  ["FreeType Linkage"]=>
  string(13) "with freetype"
  ["GIF Read Support"]=>
  bool(true)
  ["GIF Create Support"]=>
  bool(true)
  ["JPEG Support"]=>
  bool(true)
  ["PNG Support"]=>
  bool(true)
  ["WBMP Support"]=>
  bool(true)
  ["XPM Support"]=>
  bool(false)
  ["XBM Support"]=>
  bool(true)
  ["WebP Support"]=>
  bool(false)
  ["BMP Support"]=>
  bool(true)
  ["AVIF Support"]=>
  bool(false)
  ["TGA Read Support"]=>
  bool(true)
  ["JIS-mapped Japanese Font Support"]=>
  bool(false)

相关问题