簡體   English   中英

嘗試在Docker官方圖片中將freetype添加到php-gd

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

我正在嘗試向 PHP GD 安裝添加一些功能。 我使用 Docker PHP “官方”版本作為基礎 (php:7.1.15-fpm-jessie)。

我目前的生產環境使用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

但是這張 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

我需要重新編譯 PHP 還是只需要擴展? 圖片使用 Debian Jessie。

版本(解決方案):

重新編譯后,我在這篇文章中找到了最佳解決方案:

解決了! Docker + PHP7 + GD 的問題導致“調用未定義的 function imagecreatefromjpeg()”

所以我簡單地補充說:

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

之后我的 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

將此添加到您的 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

這個對我有用。

對於使用 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

在尋找了很多來解決這個問題之后,我找到了這個設置並且工作完美

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

FROM php 7.4,應該是

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

檢查這個問題: https://github.com/docker-library/php/issues/912

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM