Reputation: 529
This is my docker file:
FROM php:8.0-fpm-buster
# 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 \
libpng-dev \
libjpeg-dev \
libfreetype6-dev \
libjpeg62-turbo-dev \
jpegoptim optipng pngquant gifsicle \
libonig-dev \
libxml2-dev \
zip \
sudo \
unzip \
npm \
nodejs \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd
but I have an error
Call to undefined function Intervention\Image\Gd\imagecreatefromjpeg()
when i try to upload a jpg image.Even I change it to:
docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-gd --with-freetype --with-jpeg \
but I have below error when I build and the above error in Laravel
configure: error: unrecognized options: --with-freetype-dir, --with-jpeg-dir, --with-gd ------ failed to solve: rpc error: code = Unknown desc = executor failed running [/bin/sh -c apt-get update && apt-get install -y
build-essential git curl libpng-dev libjpeg-dev
libfreetype6-dev libjpeg62-turbo-dev jpegoptim optipng pngquant gifsicle libonig-dev libxml2-dev zip sudo
unzip npm nodejs && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-gd --with-freetype --with-jpeg && docker-php-ext-install -j$(nproc) gd]: exit code: 1
how can I fix this?
Upvotes: 7
Views: 14039
Reputation: 408
Faced similar issue in a php5.6(laravel5) project. Modified Robert's answer for my installation. Dockerfile:
RUN apt-get install -y libmagickwand-dev
RUN pecl install imagick
RUN docker-php-ext-enable imagick
If the config/image.php doesn't exist,
php artisan vendor:publish --provider="Intervention\Image\ImageServiceProviderLaravel5"
Now open config/image.php and change driver from gd to imagick.
return [
'driver' => 'imagick',
];
clear config cache:
artisan config:clear
Upvotes: 0
Reputation: 29
I was still getting the same error even after trying the accepted answer. What solved the error for me was changing the driver from GD to Imagick, which I found how to do in this answer.
Add the following to the Dockerfile:
RUN apt-get install -y libmagickwand-dev
RUN pecl install imagick
RUN docker-php-ext-enable imagick
Add this line to the PHP code before calling functions from the Intervention/Image package (Image::make
, etc.).
Image::configure(['driver' => 'imagick']);
Upvotes: 1
Reputation: 529
I fix it by enabling the GD lib, here is my Dockerfile configs:
FROM php:8.0-fpm-buster
# 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 \
libpng-dev \
libjpeg-dev \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libgd-dev \
jpegoptim optipng pngquant gifsicle \
libonig-dev \
libxml2-dev \
zip \
sudo \
unzip \
npm \
nodejs
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install PHP extensions
RUN docker-php-ext-configure gd --enable-gd --with-freetype --with-jpeg
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd
Upvotes: 20