简体   繁体   English

尝试在Docker官方图片中将freetype添加到php-gd

[英]Trying to add freetype to php-gd in Docker official image

I'm trying to add some features to PHP GD installation.我正在尝试向 PHP GD 安装添加一些功能。 I'm using Docker PHP "Official" release as base (php:7.1.15-fpm-jessie).我使用 Docker PHP “官方”版本作为基础 (php:7.1.15-fpm-jessie)。

My current production environment uses CentOS, which GD module comes with FreeType, JPEG and PNG support, as you can see in the phpinfo output:我目前的生产环境使用CentOS,其中GD模块自带FreeType、JPEG和PNG支持,在phpinfo output中可以看到:

GD Support => enabled
GD headers Version => 2.2.5
GD library Version => 2.2.5
FreeType Support => enabled
FreeType Linkage => with freetype
FreeType Version => 2.4.11
GIF Read Support => enabled
GIF Create Support => enabled
JPEG Support => enabled
libJPEG Version => 6b
PNG Support => enabled
libPNG Version => 1.5.13
WBMP Support => enabled
XPM Support => enabled
libXpm Version => 30411
XBM Support => enabled
WebP Support => enabled

Directive => Local Value => Master Value
gd.jpeg_ignore_warning => 1 => 1

But this Docker image comes without FreeType and JPEG support and with a much older version of GD (see phpinfo bellow):但是这张 Docker 图像没有 FreeType 和 JPEG 支持,并且带有更旧版本的 GD(请参阅下面的 phpinfo):

GD Support => enabled
GD Version => bundled (2.1.0 compatible)
GIF Read Support => enabled
GIF Create Support => enabled
PNG Support => enabled
libPNG Version => 1.2.50
WBMP Support => enabled
XBM Support => enabled

Directive => Local Value => Master Value
gd.jpeg_ignore_warning => 1 => 1

Do I need to recompile PHP or just the extension?我需要重新编译 PHP 还是只需要扩展? The image uses Debian Jessie.图片使用 Debian Jessie。

EDITION (SOLUTION):版本(解决方案):

After recompiling I found the best solution in this post:重新编译后,我在这篇文章中找到了最佳解决方案:

solved! 解决了! Troubles with Docker + PHP7 + GD resulting in "Call to undefined function imagecreatefromjpeg()" Docker + PHP7 + GD 的问题导致“调用未定义的 function imagecreatefromjpeg()”

So I simply added:所以我简单地补充说:

RUN apt-get update && apt-get install libgd3 libgd-dev && rm -rf /var/lib/apt/lists/*
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
RUN docker-php-ext-install -j$(nproc) gd

After that my phpinfo start to show:之后我的 phpinfo 开始显示:

GD Support => enabled
GD Version => bundled (2.1.0 compatible)
FreeType Support => enabled
FreeType Linkage => with freetype
FreeType Version => 2.5.2
GIF Read Support => enabled
GIF Create Support => enabled
JPEG Support => enabled
libJPEG Version => 6b
PNG Support => enabled
libPNG Version => 1.2.50

Add this to your Dockerfile:将此添加到您的 Dockerfile:

RUN apt-get update && apt-get install -y libpng-dev 
RUN apt-get install -y \
    libwebp-dev \
    libjpeg62-turbo-dev \
    libpng-dev libxpm-dev \
    libfreetype6-dev

RUN docker-php-ext-configure gd \
    --with-gd \
    --with-webp-dir \
    --with-jpeg-dir \
    --with-png-dir \
    --with-zlib-dir \
    --with-xpm-dir \
    --with-freetype-dir \
    --enable-gd-native-ttf

RUN docker-php-ext-install gd

It works for me.这个对我有用。

for me with php7.3, remove --enable-gd-native-ttf if works for me对于使用 php7.3 的我,如果对我有用,请删除 --enable-gd-native-ttf

RUN apt-get update && apt-get install -y libpng-dev 
RUN apt-get install -y \
    libwebp-dev \
    libjpeg62-turbo-dev \
    libpng-dev libxpm-dev \
    libfreetype6-dev

RUN docker-php-ext-configure gd \
    --with-gd \
    --with-webp-dir \
    --with-jpeg-dir \
    --with-png-dir \
    --with-zlib-dir \
    --with-xpm-dir \
    --with-freetype-dir

RUN docker-php-ext-install gd

After looking a lot for to solve this problem, I have found this settings and is working perfect在寻找了很多来解决这个问题之后,我找到了这个设置并且工作完美

FROM php:7.2-fpm
RUN apt-get update && apt-get install -y \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libpng-dev \
    && docker-php-ext-install -j$(nproc) iconv \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install -j$(nproc) gd

https://forums.docker.com/t/problems-installing-gd-on-php7-2-with-docker-docker-version-18-09-7-build-2d0083d/78400/2 https://forums.docker.com/t/problems-installing-gd-on-php7-2-with-docker-docker-version-18-09-7-build-2d0083d/78400/2

FROM php 7.4, it should be FROM php 7.4,应该是

docker-php-ext-configure gd --with-freetype --with-jpeg

Check this issue: https://github.com/docker-library/php/issues/912检查这个问题: https://github.com/docker-library/php/issues/912

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM