title: Trying to build PHP and GD with PNG and JPEG support
body: <p>The browser displays the error message </p>
  
  <blockquote>
    <p>Fatal error: Call to undefined function imagecreatefrompng() in...</p>
  </blockquote>
  
  <p>Here is the source code that fails:</p>
  
  <pre><code>$img = imagecreatefrompng($file);
  </code></pre>
  
  <p>It's a native PHP function.</p>
  
  <p>I am intent on building both GD and PHP.</p>
  
  <p>The GD <code>libgd-2.2.4</code> library was built just fine:</p>
  
  <pre><code>Support for Zlib:                 yes
  Support for PNG library:          yes
  Support for JPEG library:         yes
  Support for WebP library:         no
  Support for TIFF library:         no
  Support for Freetype 2.x library: yes
  Support for Fontconfig library:   no
  Support for Xpm library:          yes
  Support for liq library:          no
  Support for pthreads:             yes
  </code></pre>
  
  <p>I used the commands:</p>
  
  <pre><code>./configure \
    --prefix=/home/stephane/programs/install \
    --with-jpeg=/home/stephane/programs/install \
    --with-png=/home/stephane/programs/install \
    --with-freetype=/home/stephane/programs/install \
    --with-zlib=/home/stephane/programs/install \
    --with-xpm
  
  make
  make install
  </code></pre>
  
  <p>The <code>make</code> and <code>make install</code> commands were successful.</p>
  
  <p>The PHP <code>php-5.6.30</code> engine was also built fine:</p>
  
  <pre><code>checking for GD support... yes
  checking for the location of libvpx... no
  checking for the location of libjpeg... /home/stephane/programs/install
  checking for the location of libpng... /home/stephane/programs/install
  checking for the location of libXpm... no
  checking for FreeType 2... /home/stephane/programs/install
  checking for T1lib support... no
  checking whether to enable truetype string function in GD... yes
  
  checking for gdSetErrorMethod in -lgd... yes
  checking for gdImageCreateFromPng in -lgd... yes
  checking for gdImageCreateFromWebp in -lgd... no
  checking for gdImageCreateFromJpeg in -lgd... yes
  checking for gdImageCreateFromXpm in -lgd... yes
  checking for gdImageStringFT in -lgd... yes
  checking for gdVersionString in -lgd... yes
  checking for gdImageCreate in -lgd... yes
  </code></pre>
  
  <p>I used the commands:</p>
  
  <pre><code>./configure \
    --prefix=/home/stephane/programs/install \
    --with-apxs2=/home/stephane/programs/install/apache/bin/apxs \
    --with-config-file-path=/home/stephane/programs/php-5.6.30/ \
    --with-mysql=/home/stephane/programs/install/mariadb \
    --with-mysqli=/home/stephane/programs/install/mariadb/bin/mysql_config \
    --with-pdo-mysql=/home/stephane/programs/install/mariadb \
    --with-zlib-dir=/home/stephane/programs/install \
    --with-jpeg-dir=/home/stephane/programs/install \
    --with-png-dir=/home/stephane/programs/install \
    --with-gd=/home/stephane/programs/install \
    --enable-gd-native-ttf \
    --with-freetype-dir=/home/stephane/programs/install \
    --enable-ftp \
    --enable-xml \
    --enable-zip \
    --with-bz2 \
    --enable-wddx \
    --enable-libgcc \
    --without-pear \
    --enable-mbstring \
    --enable-intl \
    --enable-calendar \
    --with-openssl \
    --with-curl \
    --enable-debug \
    --disable-phar \
    --enable-fpm \
    --with-oci8=instantclient,/home/stephane/programs/oracle/instantclient_11_2
  
  make
  make install
  </code></pre>
  
  <p>The <code>make</code> and <code>make install</code> commands were also successful.</p>
  
  <p>Here are the library files that were created:</p>
  
  <pre><code>$ ll /home/stephane/programs/install/lib/
  total 22M
  -rw-r--r-- 1 stephane 6,3M juin  12 14:30 libfreetype.a
  -rwxr-xr-x 1 stephane 1,1K juin  12 14:30 libfreetype.la*
  lrwxrwxrwx 1 stephane   21 juin  12 14:30 libfreetype.so -&gt; libfreetype.so.6.13.0*
  lrwxrwxrwx 1 stephane   21 juin  12 14:30 libfreetype.so.6 -&gt; libfreetype.so.6.14.0*
  -rwxr-xr-x 1 stephane 3,0M juin  12 14:30 libfreetype.so.6.13.0*
  -rwxr-xr-x 1 stephane 3,1M juin  10 13:11 libfreetype.so.6.14.0*
  -rw-r--r-- 1 stephane 1,7M juin  12 15:08 libgd.a
  -rwxr-xr-x 1 stephane 1,2K juin  12 15:08 libgd.la*
  lrwxrwxrwx 1 stephane   14 juin  12 15:08 libgd.so -&gt; libgd.so.3.0.4*
  lrwxrwxrwx 1 stephane   14 juin  12 15:08 libgd.so.3 -&gt; libgd.so.3.0.4*
  -rwxr-xr-x 1 stephane 1,1M juin  12 15:08 libgd.so.3.0.4*
  -rw-r--r-- 1 stephane 2,2M juin   7 12:36 libjpeg.a
  -rwxr-xr-x 1 stephane  938 juin   7 12:36 libjpeg.la*
  lrwxrwxrwx 1 stephane   16 juin   7 12:36 libjpeg.so -&gt; libjpeg.so.9.2.0*
  lrwxrwxrwx 1 stephane   16 juin   7 12:36 libjpeg.so.9 -&gt; libjpeg.so.9.2.0*
  -rwxr-xr-x 1 stephane 1,2M juin   7 12:36 libjpeg.so.9.2.0*
  -rw-r--r-- 1 stephane 1,7M juin  10 12:43 libpng16.a
  -rwxr-xr-x 1 stephane  958 juin  10 12:43 libpng16.la*
  lrwxrwxrwx 1 stephane   19 juin  10 12:43 libpng16.so -&gt; libpng16.so.16.29.0*
  lrwxrwxrwx 1 stephane   19 juin  10 12:43 libpng16.so.16 -&gt; libpng16.so.16.29.0*
  -rwxr-xr-x 1 stephane 905K juin  10 12:43 libpng16.so.16.29.0*
  lrwxrwxrwx 1 stephane   10 juin  10 12:43 libpng.a -&gt; libpng16.a
  lrwxrwxrwx 1 stephane   11 juin  10 12:43 libpng.la -&gt; libpng16.la*
  lrwxrwxrwx 1 stephane   11 juin  10 12:43 libpng.so -&gt; libpng16.so*
  -rw-r--r-- 1 stephane 151K juin   5 22:46 libz.a
  lrwxrwxrwx 1 stephane   14 juin   5 22:46 libz.so -&gt; libz.so.1.2.11*
  lrwxrwxrwx 1 stephane   14 juin   5 22:46 libz.so.1 -&gt; libz.so.1.2.11*
  -rwxr-xr-x 1 stephane 120K juin   5 22:46 libz.so.1.2.11*
  drwxrwxr-x 4 stephane 4,0K juin   8 17:08 php/
  drwxrwxr-x 2 stephane 4,0K juin  12 15:08 pkgconfig/
  </code></pre>
  
  <p>But a look at the <code>phpinfo</code> shows an incomplete GD section:</p>
  
  <pre><code>GD Support  enabled
  GD headers Version  2.2.4
  GD library Version  2.2.4
  GIF Read Support    enabled
  GIF Create Support  enabled
  WBMP Support    enabled
  XPM Support enabled
  libXpm Version  30411
  XBM Support enabled
  </code></pre>
  
  <p>There are no default packages installed:</p>
  
  <pre><code>$ sudo apt-cache show libpng
  N: Impossible de trouver le paquet libpng
  E: Aucun paquet n'a été trouvé
  [stephane@stephane-ThinkPad-X201 fatec]
  $ sudo apt-cache show libjpeg
  N: Impossible de trouver le paquet libjpeg
  E: Aucun paquet n'a été trouvé
  </code></pre>
  
  <p>Here is a bit about my OS and machine:</p>
  
  <pre><code>$ uname -a
  Linux stephane-ThinkPad-X201 4.4.0-79-generic #100-Ubuntu SMP Wed May 17 19:58:14 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
  </code></pre>
  
  <p>My Apache configuration does point to the right PHP directory:</p>
  
  <pre><code>&lt;IfModule mod_php5.c&gt;
      PHPIniDir "/home/stephane/programs/php-5.6.30"
  &lt;/IfModule&gt;
  
  $ ll /home/stephane/programs/php-5.6.30/php.ini
  -rw-r--r-- 1 stephane 73K juin  12 14:05 /home/stephane/programs/php-5.6.30/php.ini
  </code></pre>