Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GD not support JPEG

Tags:

php

docker

I tried enabling GD JPEG with DOCKER but it doesn't work. This is my dockerfile :

FROM php:7.4-apache
COPY ./app/. /var/www/html
RUN apt-get update && apt-get install -y  \
    libzip-dev zip \
    zlib1g-dev \
    libjpeg-dev \
    libjpeg62-turbo-dev \
    libfreetype6-dev \
    libpng-dev


RUN docker-php-ext-install mysqli && a2enmod rewrite && service apache2 restart && chown -R www-data:www-data /var/www

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

RUN docker-php-ext-install zip && docker-php-ext-install -j$(nproc) gd

But the result remains the same:

# php -r "print_r(gd_info());"
Array
(
    [GD Version] => bundled (2.1.0 compatible)
    [FreeType Support] =>
    [GIF Read Support] => 1
    [GIF Create Support] => 1
    [JPEG Support] =>
    [PNG Support] => 1
    [WBMP Support] => 1
    [XPM Support] =>
    [XBM Support] => 1
    [WebP Support] =>
    [BMP Support] => 1
    [TGA Read Support] => 1
    [JIS-mapped Japanese Font Support] =>
)

JPEG Support is still false.

like image 610
Fahri Bullseye Avatar asked Feb 04 '26 12:02

Fahri Bullseye


2 Answers

Try installing the extensions [step 5/5] with a single execution of a docker-php-ext-install, just append to the end:

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

result:

root@b83821be0bcf:/var/www/html# php -r "print_r(gd_info());"
Array
(
    [GD Version] => bundled (2.1.0 compatible)
    [FreeType Support] => 1
    [FreeType Linkage] => with freetype
    [GIF Read Support] => 1
    [GIF Create Support] => 1
    [JPEG Support] => 1
    [PNG Support] => 1
    [WBMP Support] => 1
    [XPM Support] =>
    [XBM Support] => 1
    [WebP Support] =>
    [BMP Support] => 1
    [TGA Read Support] => 1
    [JIS-mapped Japanese Font Support] =>
)
root@b83821be0bcf:/var/www/html#

Read this bug for details.

like image 75
jabbson Avatar answered Feb 07 '26 02:02

jabbson


I have the same problem for PHP 7.4 in docker and spent a lot of hours looking for a solution.

The only one worked with me is:

  1. Install LibJPEG Library manually1:
$ wget http://www.ijg.org/files/jpegsrc.v9.tar.gz
$ tar xvfz jpegsrc.v9.tar.gz
$ cd jpeg-9
$ ./configure
$ make
$ make install
  1. Configure GD extension to use that library:
docker-php-ext-configure gd --enable-gd --with-freetype --with-jpeg=/usr/local/lib
  1. Install GD extension
$ docker-php-ext-install gd

References:

  1. https://www.thegeekstuff.com/2013/10/enable-gd-php/
like image 36
wajdi_jurry Avatar answered Feb 07 '26 00:02

wajdi_jurry