Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk9 min

How to Install and Enable the GD Image Library for PHP

A version-aware guide to installing PHP’s GD image library on Windows, in source builds and through operating-system packages, with verification and troubleshooting for CLI and web runtimes.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The correct way to install PHP’s GD image library depends on how PHP itself was installed. Windows builds load the bundled php_gd.dll from php.ini; source builds enable GD with version-appropriate configure flags and development libraries; package-managed installations require the GD package that matches your PHP version and operating system. After changing configuration, restart the PHP-serving process and verify the web runtime separately from the command-line runtime.

What PHP GD is and why installation varies

GD is a PHP extension that supplies functions for creating, resizing, cropping, drawing and exporting raster images. It is not a separate application that every PHP installation discovers automatically. The extension must be compiled into PHP or loaded as a shared module, and its available image formats are determined by the libraries and switches selected during the build.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

That is why an instruction written for a Windows binary cannot be copied to a source build, and why a command for one Linux distribution may not apply to another. Start by identifying the PHP runtime used by the application and the way that runtime was installed.

PHP installation route GD installation or activation method Most important qualification
Windows binary Enable the bundled DLL in the active php.ini PHP 8.0 and later use php_gd.dll; releases before PHP 8.0 used php_gd2.dll
Source build on Unix-like systems Install development libraries, then configure and compile PHP with the flags for that PHP release Current releases use --enable-gd; optional formats are build-time choices
Operating-system package Install the distribution’s GD package matching the PHP version and SAPI Package names and restart commands differ by distribution, release and PHP version

Check the PHP version, SAPI and active configuration first

Before changing anything, establish which PHP executable and configuration your application actually uses. A command-line PHP binary can have a different version, extension directory and php.ini from Apache, PHP-FPM or another web-server integration.

  1. Run php --version to record the CLI PHP version.
  2. Run php --ini to see the CLI configuration file and additional scanned configuration directories.
  3. Run php -m and look for gd. If it is already listed, GD is enabled for that CLI binary.
  4. For a website, inspect the web runtime rather than assuming it uses the CLI settings. A temporary diagnostic page containing <?php phpinfo(); shows the web server’s PHP version, loaded configuration file and GD section. Remove that page immediately after testing.

Record the PHP minor version (for example, 7.4, 8.0 or 8.1), because configure option names changed in PHP 7.4 and AVIF support was added as an option in PHP 8.1.

Windows: enable the bundled GD DLL

Windows PHP distributions include the GD module as a DLL. You normally do not compile GD yourself; you enable the DLL in the configuration file used by the PHP process serving your application.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

1. Find the configuration file that the application uses

php --ini reports the file used by the CLI executable. That file may not be the one used by a web server. Use the web runtime’s diagnostic output to identify the active php.ini when the website and CLI disagree.

2. Enable the correct DLL name

Open the active php.ini and enable the GD extension line. PHP 8.0 and later use:

extension=php_gd.dll

PHP releases before 8.0 used the legacy filename:

extension=php_gd2.dll

Use the filename that exists in the PHP installation’s extension directory and matches the PHP release. Do not enable both names at once. If the line is commented, remove the comment marker; if it is absent, add the appropriate extension entry in the extensions section.

3. Restart the serving process

PHP reads php.ini when the process starts. Restart the web server, PHP-FPM process or other PHP-serving process after saving the file. A browser refresh alone does not reload a long-running PHP worker.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

4. Verify from both environments

For the CLI, run:

php -m

On Windows, you can filter the result with:

php -m | findstr /I gd

Then check the website with a temporary script:

<?php
var_dump(extension_loaded('gd'));
var_dump(function_exists('imagecreatetruecolor'));

Both values should be true. Delete the diagnostic script when the check is complete.

Source builds on Unix-like systems

When PHP is compiled from source, GD is selected during the configure step. The PHP Manual states that GD compilation requires libpng and libjpeg. PNG support also requires zlib. You need the development headers and libraries, not merely runtime image packages.

Required libraries

  • libpng: required for PNG support and required by a GD source build.
  • libjpeg: required by a GD source build and for JPEG support.
  • zlib: required for PNG support.

Development-package names vary between operating systems, so identify your distribution and PHP release before installing them. After installing or changing a library, rerun configuration so PHP detects the new headers and linker files.

Configure flags in PHP 7.4 and later

From PHP 7.4 onward, --enable-gd controls whether the GD extension is enabled. The separate --with-external-gd option tells PHP to use an external libgd instead of the bundled library. These choices are not interchangeable:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Purpose Flag When to use it
Enable GD with the bundled library --enable-gd Normal source builds that use the libgd supplied with PHP
Use an external libgd --with-external-gd together with --enable-gd Only when the system’s external libgd is intentionally required and compatible
JPEG support --with-jpeg PHP 7.4 and later, when JPEG support is needed
WebP support --with-webp When the required WebP development library is available
XPM support --with-xpm When XPM images are required and the XPM library is available
AVIF support --with-avif Available from PHP 8.1.0; requires the corresponding AVIF capability
FreeType text rendering --with-freetype PHP 7.4 and later; detection relies on pkg-config

Do not add every switch automatically. Each optional switch is a build-time request for a capability and can fail if its development library or detection metadata is missing.

Older PHP releases

Older manuals may show --with-gd and directory-oriented forms such as --with-jpeg-dir, --with-webp-dir or --with-xpm-dir. PHP 7.4 changed several of these names. Use the configure syntax documented for the exact PHP release you are compiling; copying a current flag into an older release, or an old *-dir flag into a current release, can make configuration fail or silently omit a capability.

Run configure with only the features you need

A typical PHP 7.4-or-newer build that needs JPEG, WebP and FreeType might include:

./configure --enable-gd --with-jpeg --with-webp --with-freetype

For a build that deliberately uses an external libgd, the relevant combination is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
./configure --enable-gd --with-external-gd --with-jpeg --with-webp --with-freetype

These are configure-stage examples, not complete PHP build recipes. Keep the rest of your existing PHP configure options, and add only switches supported by the PHP version and libraries installed on the machine. If AVIF is needed and the build is PHP 8.1.0 or newer, add --with-avif.

Compile, install and restart

  1. Install the libpng and libjpeg development files; add zlib and any optional format or FreeType development files required by your selected switches.
  2. Run ./configure with the version-appropriate GD flags.
  3. Review the configure summary for GD and the requested formats before compiling. A missing library can cause a configure error or leave a capability disabled.
  4. Compile and install PHP using the same build procedure and prefix as the existing installation.
  5. Restart the PHP-serving process so it loads the newly installed binary or module.
  6. Verify the CLI and web runtimes independently.

The PHP Manual warns that the libpng version used when compiling PHP must match the version linked with GD. If those versions differ, rebuild with a consistent libpng installation rather than treating the warning as harmless.

Package-managed PHP

Distribution packages are usually the simplest route when PHP came from an operating-system repository, but the package name and service-management command are distribution-specific. The canonical PHP installation documentation does not provide one command that is correct for every distribution and PHP version.

  1. Identify the operating system, release, PHP minor version and SAPI (CLI, Apache module or PHP-FPM).
  2. Use that distribution’s package manager to locate the GD package matching the PHP version. Avoid installing a package for a different PHP minor release.
  3. Install the package and note whether it supplies a module, a replacement PHP build or both.
  4. Restart the PHP-serving process named by the distribution’s documentation.
  5. Run php -m for the CLI and use a web-runtime diagnostic page for the application. If only one shows GD, the two SAPIs are using different PHP installations or configuration files.

Do not assume that installing a CLI package changes a separately managed PHP-FPM or web-server runtime. The loaded configuration and extension list are the evidence that matters.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Verify that GD and the required formats are really available

CLI verification

Run php -m and confirm that gd appears. To inspect the loaded configuration, use php --ini. A more focused diagnostic script can report the extension and its capabilities:

<?php
var_dump(extension_loaded('gd'));
var_dump(function_exists('gd_info'));
if (function_exists('gd_info')) {
print_r(gd_info());
}

The gd_info() output identifies capabilities exposed by the loaded build. Check it when the application needs a particular format rather than assuming that installing GD enables every format.

Web-runtime verification

Place the same checks in a temporary page served by the application’s actual web server. This catches the common case in which the CLI has GD but the website runs another PHP version or another php.ini. Keep diagnostic pages private and remove them after testing because configuration output can disclose paths and environment details.

Functional smoke test

Checking that imagecreatetruecolor exists confirms that a core GD function can be called. A real application should also exercise the formats it depends on—for example, its PNG, JPEG or WebP upload and thumbnail path—because GD can be loaded while a particular optional capability is absent.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting common failures

“Call to undefined function imagecreatetruecolor()”

The code is running without GD in that PHP runtime. Check extension_loaded('gd'), inspect the web runtime’s active php.ini, enable or install the module there, and restart the serving process.

GD appears in CLI output but not on the website

This indicates different PHP configurations or SAPIs. Compare the PHP version, loaded configuration file and extension list from the CLI and a temporary web diagnostic page. Make the change in the configuration actually used by the website; changing the CLI file alone will not fix the web process.

Windows reports that the GD DLL cannot be loaded

Confirm the filename for the PHP generation: php_gd.dll for PHP 8.0 and later, or php_gd2.dll before PHP 8.0. Check that the extension entry is in the active php.ini, then restart the serving process. A DLL from a different PHP installation or release is not a substitute for the bundled module.

Configure cannot find PNG or JPEG libraries

The runtime libraries alone are insufficient for a source build. Install the corresponding development headers and linker files, rerun ./configure, and inspect the configuration summary. PNG support also needs zlib.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Configuration warns about incompatible libpng versions

Use a single, consistent libpng version for the PHP build and GD link. The manual specifically warns that the libpng version compiled with PHP must match the version linked with GD. Cleanly reconfigure and rebuild after correcting the library paths.

GD loads but WebP, AVIF, XPM or FreeType is missing

Those capabilities are optional. Confirm that the PHP release supports the switch, that the corresponding development library is installed, and that the switch was present during configuration. AVIF’s GD switch is available from PHP 8.1.0; FreeType uses --with-freetype from PHP 7.4 onward and relies on pkg-config. A capability omitted at build time cannot normally be enabled by editing php.ini.

The change has no effect after editing php.ini

PHP reads configuration at process startup. Restart the relevant web server, PHP-FPM process or other PHP-serving process, and verify the loaded configuration again. If the restart did not change the reported file or extension list, you edited a configuration that the application does not use.

Choose the right installation path

Your situation Recommended path What to verify before declaring success
Standard Windows PHP binary Enable the bundled DLL in the active php.ini Correct DLL name, process restart, GD visible in the web runtime
PHP compiled from source Install development libraries and configure GD with release-appropriate flags libpng/libjpeg requirements, zlib for PNG, optional switches and configure summary
PHP supplied by an operating-system repository Install the matching distribution GD package Package matches PHP minor version and SAPI; restart command is distribution-specific
CLI works but the application fails Diagnose the web SAPI independently Web version, php.ini path and extension list, not just CLI output

Final checklist

  • Identify the PHP version and the runtime that serves the application.
  • Use the installation method that matches PHP: DLL activation, source compilation or a distribution package.
  • For source builds, provide libpng and libjpeg; add zlib for PNG support.
  • Use --enable-gd for current source builds and add --with-external-gd only when an external libgd is intentional.
  • Use optional format and FreeType switches only when the PHP version and required libraries support them.
  • Remember that PHP 7.4 changed several configure option names and that AVIF support begins with PHP 8.1.0.
  • On Windows, select php_gd.dll from PHP 8.0 onward and php_gd2.dll before PHP 8.0.
  • Restart the serving process and test both CLI and web configurations.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.