Docker + PHP7 + GD的问题导致“调用未定义的函数imagecreatefromjpeg()”。 [英] Troubles with Docker + PHP7 + GD resulting in "Call to undefined function imagecreatefromjpeg()"

查看:763
本文介绍了Docker + PHP7 + GD的问题导致“调用未定义的函数imagecreatefromjpeg()”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用 Dockerfile 使用 imagecreatefromjpeg 创建映像时遇到麻烦:

I'm having troubles when trying to create an image using imagecreatefromjpeg using this Dockerfile to generate the container:

FROM  php:7.1-apache

RUN apt-get update && \
    apt-get install -y -qq git \
        libjpeg62-turbo-dev \
        apt-transport-https \
        libfreetype6-dev \
        libmcrypt-dev \
        libpng12-dev \
        libssl-dev \
        zip unzip \
        nodejs \
        npm \
        wget \
        vim

RUN pecl install redis && docker-php-ext-enable redis
RUN docker-php-ext-install -j$(nproc) iconv mcrypt zip pdo pdo_mysql gd bcmath

COPY ./containers/yii.conf /etc/apache2/sites-available/000-default.conf

RUN for mod in rewrite headers; do a2enmod $mod; done && service apache2 restart

WORKDIR /var/www/html/

GD已正确安装(libjpeg同样-都出现在 php -i phpinfo())中,但出现在 imagecreatefromjpeg 不起作用,我也不知道为什么。

GD was correctly installed (libjpeg too - both appearing in php -i and phpinfo()) but imagecreatefromjpeg does not works and I don't know why.

我还运行了 apt install libjpeg-dev libpng- dev libfreetype6-dev 试图〜强制〜重新安装(或重新配置),但似乎没有成功(是的,我也重新启动了容器)。

I also ran apt install libjpeg-dev libpng-dev libfreetype6-dev trying to ~force~ reinstallation (or reconfiguration) but seems doesn't succeded (yes, I also restart the container).

root@e8db647c96c4:/var/www/html# php -i | grep -i GD
/usr/local/etc/php/conf.d/docker-php-ext-gd.ini,
gd
GD Support => enabled
GD Version => bundled (2.1.0 compatible)
gd.jpeg_ignore_warning => 1 => 1
root@e8db647c96c4:/var/www/html# 





root@e8db647c96c4:/var/www/html# docker-php-ext-enable gd

warning: gd (gd.so) is already loaded!

root@e8db647c96c4:/var/www/html# 




我试过 apt安装libgd2-xpm-dev * ,显然它不能解决问题。


I've tried apt install libgd2-xpm-dev* and apparently it doesn't solves the problem.

我想放

RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
RUN docker-php-ext-install -j$(nproc) gd

到我的Dockerfile中。

into my Dockerfile.

完整修订的Dockerfile:

Full revised Dockerfile:

FROM  php:7.1-apache

RUN apt-get update && \
    apt-get install -y -qq git \
        libjpeg62-turbo-dev \
        apt-transport-https \
        libfreetype6-dev \
        libmcrypt-dev \
        libpng12-dev \
        libssl-dev \
        zip unzip \
        nodejs \
        npm \
        wget \
        vim

RUN pecl install redis && docker-php-ext-enable redis
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
RUN docker-php-ext-install -j$(nproc) iconv mcrypt zip pdo pdo_mysql gd bcmath

COPY ./containers/yii.conf /etc/apache2/sites-available/000-default.conf

RUN for mod in rewrite headers; do a2enmod $mod; done && service apache2 restart

WORKDIR /var/www/html/


推荐答案

PHP 7.4(高山)



如果有人正在努力使用 PHP 7.4 在GD中启用JPEG支持,则我必须要做的才能使用 imagecreatefromjpeg()函数。
我的示例基于Alpine 3.10,如果您使用其他发行版,请根据需要进行调整。

PHP 7.4 (Alpine)

If anybody is struggling to enable JPEG support in GD with PHP 7.4, here's what I had to do in order to be able to use imagecreatefromjpeg() function. My example is based on Alpine 3.10, if you're using other distribution adjust it to your needs.

首先安装依赖项,在我的例子中是JPEG I需要对PNG文件的支持。

First install dependencies, in my case beside JPEG I need support for PNG files.

apk add jpeg-dev libpng-dev

之后,我们可以运行 docker-php-ext-configure 命令为我们的gd配置JPEG支持。请注意,标志-with-jpeg-dir 已更改为-with-jpeg ,我们不需要提供标志以启用PNG。您可以在GD部分的 PHP 7.4更改日志中了解更多信息。

After that we can run docker-php-ext-configure command to configure our gd with JPEG support. Notice that flag --with-jpeg-dir was changed to --with-jpeg and we don't need to provide flag to enable PNG. More you can read in PHP 7.4 Changelog in GD section.

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

之后,让我们直接运行 docker-php-ext-install 来安装GD本身。

Directly after that let's run docker-php-ext-install to install GD itself.

docker-php-ext-install -j$(nproc) gd

完整示例

FROM php:7.4-fpm-alpine3.10

RUN apk add jpeg-dev libpng-dev \
    && docker-php-ext-configure gd --with-jpeg \
    && docker-php-ext-install -j$(nproc) gd

这篇关于Docker + PHP7 + GD的问题导致“调用未定义的函数imagecreatefromjpeg()”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆