I am using Laravel with the docker PHP:7.3-fpm
image.
I get the issue Call to undefined function Intervention\Image\Gd\imagejpeg()"
when using Image Intervention Package like this:
$avatar = \Image::make($image->getRealPath());
$avatar->fit(221, 146)->encode('jpg', 80);
Here is the full error message:
exception: Symfony\Component\Debug\Exception\FatalThrowableError^ {#8221
-originalClassName: "Error"
#message: "Call to undefined function Intervention\Image\Gd\imagejpeg()"
#code: 0
#file: "/var/www/vendor/intervention/image/src/Intervention/Image/Gd/Encoder.php"
#line: 17
#severity: E_ERROR
trace: {
/var/www/vendor/intervention/image/src/Intervention/Image/Gd/Encoder.php:17 { …}
/var/www/vendor/intervention/image/src/Intervention/Image/AbstractEncoder.php:123 { …}
/var/www/vendor/intervention/image/src/Intervention/Image/AbstractDriver.php:79 { …}
/var/www/vendor/intervention/image/src/Intervention/Image/Image.php:121 { …}
/var/www/app/Repositories/MediaRepository.php:37 {
App\Repositories\MediaRepository->addGalleryToTraining(array $images): void^
›
› $avatar->fit(221, 146)->encode('jpg', 80);
› $avatar_path = 'trainings/gallery/' . $gallery->id . '/avatars/' . $image->hashName();
arguments: {
$format: "jpg"
$quality: 80
}
}
Line 17 of Gd/Encoder.php
is this:
imagejpeg($this->image->getCore(), null, $this->quality);
I found here that I should install GD with jpg / png support. However, the answer there was for the php:7.2-fpm-alpine
image. Since I don't use the image, I can't apply it the apk add libjpg ..
solution.
I also found here which uses the PHP:7.2-fpm
image and claims to fix jpg issues.
I used
RUN apt-get install -y build-essential libssl-dev zlib1g-dev libpng-dev libjpeg-dev libfreetype6-dev
and
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install gd
from that solution, but I still get the above error. Here is my complete Dockerfile:
FROM php:7.3-fpm
# Arguments defined in docker-compose.yml
ARG user
ARG uid
# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
git \
curl \
libssl-dev \
zlib1g-dev \
libpng-dev \
libjpeg-dev \
libfreetype6-dev \
libonig-dev \
libxml2-dev \
libicu-dev \
zip \
unzip \
libzip-dev \
-y mariadb-client
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install PHP extensions
RUN docker-php-ext-install zip mysqli soap pdo_mysql mbstring exif pcntl bcmath gd && docker-php-ext-enable mysqli && docker-php-ext-configure intl \
&& docker-php-ext-install \
intl \
&& docker-php-ext-enable intl
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir
RUN apt update && apt install -y libc-client-dev libkrb5-dev && rm -r /var/lib/apt/lists/*
RUN docker-php-ext-configure imap --with-kerberos --with-imap-ssl && docker-php-ext-install imap
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Create system user to run Composer and Artisan Commands
RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
chown -R $user:$user /home/$user
# Set working directory
WORKDIR /var/www
USER $user
Any idea what could cause this?