The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
Need a server to try this on? Antihost offers Linux VPS plans with NVMe storage, full root access and a 14-day free trial.
The correct way to install PHP’s GD image library depends on how PHP itself was installed. Windows builds normally enable the bundled extension in php.ini; source builds enable GD with version-appropriate configure options and development libraries; package-managed installations use the GD package supplied by the operating system.
GD is not a separate PHP application. It is an extension loaded by the PHP runtime, and the command-line runtime and the PHP process serving your website can load different configuration files. Install or enable GD for the runtime that actually executes your application, then verify that runtime’s extension list and image-format capabilities.
Choose the installation path that matches your PHP build
Before changing anything, identify how PHP was installed. The same php.ini edit cannot fix every installation, and a source-build configure flag does not apply to a precompiled Windows binary.
| PHP installation | Where GD is enabled | What you must account for |
|---|---|---|
| Windows binary | Uncomment or add the bundled GD DLL in the active php.ini. |
The DLL is named php_gd.dll in PHP 8.0 and later; releases before PHP 8.0 used php_gd2.dll. Restart the PHP-serving process after editing. |
| Source build on Unix-like systems | Configure PHP with the GD option appropriate to the PHP release, then rebuild and install PHP. | Development versions of libpng and libjpeg are required. PNG support also needs zlib. Optional format and font switches must match the libraries and the PHP version. |
| Operating-system package | Install the GD package provided for that operating system and PHP version. | Package names, repositories, service names and restart commands differ by distribution. Do not copy a command intended for another distribution. |
Confirm which PHP runtime your site uses
A server can have several PHP installations. A terminal may invoke one binary while Apache, Nginx with PHP-FPM, a control panel, or a hosting platform invokes another. Check the PHP version and configuration for the runtime you intend to change. For the command-line runtime, php --version and php --ini show the binary version and the configuration file it loads. For a web runtime, inspect the loaded configuration through the PHP information page or the hosting panel’s PHP selector, then remove any diagnostic page when finished.
#1 Best Overall
Do not assume that a successful CLI check proves that a web request can use GD. CLI PHP and web-server PHP may have different versions, extension directories, and php.ini files.
Windows: enable the bundled GD DLL
Windows PHP distributions include GD as a DLL. You normally do not compile libpng or libjpeg yourself; you enable the extension shipped with the PHP build.
Step 1: locate the active php.ini
- Find the configuration file loaded by the PHP process that serves your application. For CLI PHP, run
php --ini. For a web server, use its PHP information output or management panel because it may load a different file. - Open that active
php.iniwith an account permitted to edit the PHP installation directory. - Check that the extension directory points to the folder containing the PHP extensions, commonly through the
extension_dirsetting. A wrong extension directory can make an otherwise present DLL appear missing.
Step 2: enable the correct DLL name
In PHP 8.0 and later, enable the bundled GD extension named php_gd.dll. In a release older than PHP 8.0, the legacy filename is php_gd2.dll. Use the filename that exists in your PHP build rather than copying a line from documentation for another release.
In the extensions section of php.ini, remove the comment character from the line that references the appropriate DLL, or add the equivalent extension entry used by that PHP release. Keep only one GD entry enabled. A typical modern entry is:
extension=php_gd.dll
If your distribution’s sample configuration uses a different but equivalent extension syntax, follow that file’s convention. Do not rename a DLL, mix a DLL from another PHP version, or copy a 32-bit extension into a 64-bit PHP installation.
Step 3: restart the PHP-serving process
Save php.ini, then restart the process that loads PHP. Depending on the deployment, that may be Apache, PHP-FPM, IIS, or a hosting-panel-managed PHP service. Merely saving the file does not reload an already running worker process. Restart the relevant service through the operating system or hosting panel; the exact service name is installation-specific.
Rank #2
Step 4: verify Windows loading
Verify the same runtime used by the application. In a terminal, php -m should list gd when the CLI configuration has loaded it. A small diagnostic script can also check extension_loaded('gd') and display the GD section of phpinfo(). Run the check through the web server as well if the application is web-based. Remove a public diagnostic script after testing because it exposes configuration details.
Common Windows errors
- “Unable to load dynamic library”: confirm the DLL filename,
extension_dir, PHP architecture, and build version. An extension compiled for a different PHP release or architecture will not load. - GD appears in CLI but not in the website: the web server is loading another
php.inior another PHP installation. Compare the CLI and web-server PHP versions and configuration paths. - The line is enabled but nothing changes: restart the PHP-serving process and check its startup error log. A long-running worker can retain the old configuration until it is restarted.
- You are following an old tutorial: pre-8.0 instructions may refer to
php_gd2.dll. For PHP 8.0 and later, look forphp_gd.dll.
Source builds on Unix-like systems
When PHP is compiled from source, GD is selected at configure time. The PHP manual’s general form is --with-gd[=DIR], where DIR identifies a GD base installation directory. PHP’s configure interface changed in the 7.4 transition, so use flags that belong to the version you are compiling rather than combining options from unrelated tutorials.
Understand the PHP 7.4 and later model
For current source builds, --enable-gd enables the GD extension. If you deliberately want PHP to use an external libgd rather than the bundled library, add --with-external-gd. Older instructions that only say --with-gd may describe a different release or build arrangement; check the configure help for the exact PHP source version.
Do not enable --with-external-gd merely because a system has a libgd package. It selects an external implementation, which must be available in a form that the PHP build can find and link.
Free tools Windows power users keep installed
One-click scans. No signup required.
Install the development libraries first
GD cannot compile without the development libraries for libpng and libjpeg. The PHP documentation states: “GD library requires libpng and libjpeg to compile.” PNG support additionally requires zlib. Install the development variants, headers and link metadata supplied by your operating system, not only the runtime libraries.
Package names and commands vary among Debian-based, Red Hat-based, Alpine, BSD and other systems, and the canonical installation guidance does not define one command that is correct for all of them. Identify your distribution and PHP source version before selecting package commands. If a configure test says a header or library cannot be found, check that the corresponding development package is installed and that the compiler search path includes it.
Configure the minimum build
A minimal modern configure selection contains the GD switch and the required image libraries, using options accepted by the PHP version being built. For example, the relevant portion of a PHP 7.4-or-newer configuration may look like:
./configure --enable-gd --with-jpeg
The exact complete configure command also contains the options for your PHP installation, database drivers, web-server integration and other extensions; those are outside GD itself. Treat the snippet as the GD portion, not as a complete production PHP build recipe.
After configuring, review the summary and compiler output for GD, JPEG, PNG and zlib detection before running the normal build and installation process for that PHP source tree. If a required library is not detected, stop and correct the dependency or search path instead of proceeding with a partial build.
Add optional image formats only when needed
Image formats are build-time capabilities. Add a switch only when the required library is installed and the PHP release supports that switch:
| Capability | Configure option and version note | Dependency or caution |
|---|---|---|
| JPEG | --with-jpeg in PHP 7.4 and later. |
Requires the JPEG development library. |
| WebP | --with-webp. |
Requires WebP development support. Older PHP releases used a --with-webp-dir form. |
| XPM | --with-xpm. |
Older releases used --with-xpm-dir. |
| FreeType fonts | --with-freetype from PHP 7.4 onward. |
Detection relies on pkg-config and the FreeType development files. |
| AVIF | --with-avif, available from PHP 8.1.0. |
The PHP source version and AVIF development support must both meet the requirement. |
Older tutorials may show --with-jpeg-dir, --with-webp-dir or --with-xpm-dir. PHP 7.4 changed several option names. Do not substitute an old -dir option for a current option without checking that release’s configure help.
Keep libpng versions consistent
The libpng version used while compiling PHP must match the version linked with GD. A mismatch can cause configure or link failures, or produce a build whose PNG behavior is unreliable. Ensure that headers, libraries and pkg-config metadata all refer to the intended installation, especially when both a system library and a manually installed library are present.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minuteRank #4
Package-managed PHP: use the distribution’s GD package
Distribution packages are usually the simplest route when PHP came from an operating-system repository. Install the GD extension package corresponding to the PHP version already selected by that distribution, then restart the PHP process that serves requests.
There is no distribution-neutral package command or restart command. Package names can encode a major PHP version, and service names differ between Apache, PHP-FPM and other integrations. Using a package for a different PHP branch can install GD for a runtime your site never invokes.
A safe package workflow
- Record the PHP version used by the application and whether it runs under Apache, PHP-FPM, a command-line job, or another integration.
- Use the operating system’s package documentation to find the GD package for that PHP version. Confirm the repository and architecture are compatible with the existing PHP packages.
- Install the package through the distribution’s normal package manager. If the manager proposes replacing the PHP runtime or upgrading the major version, review that transaction before accepting it.
- Restart the PHP-serving process named by your distribution’s documentation.
- Verify both the CLI and web runtime if both are used by the application. They may still point to separate PHP installations even after the package installation succeeds.
Verify that GD and the required formats are available
“GD is installed” is not always enough. An application may need JPEG, WebP, AVIF, XPM or FreeType in addition to the base extension. Check the capabilities of the runtime that will process images.
CLI check
For a CLI application, run php -m and confirm that gd appears. You can inspect detailed configuration with php -i; look for the GD section and the reported support entries. The exact output layout varies by PHP version and build, so treat the presence of the extension and the listed format support as separate checks.
Web-server check
For a website, execute the same checks through the web-server PHP runtime, using a temporary diagnostic endpoint or the application’s own environment report. Confirm the loaded configuration file, PHP version, GD extension state and format capabilities. Delete the diagnostic endpoint after verification.
Application-level function check
A focused PHP check can test whether the extension is loaded before an image operation:
<?php
if (!extension_loaded('gd')) {
throw new RuntimeException('The GD extension is not loaded.');
}
echo function_exists('imagecreatetruecolor') ? 'GD is available' : 'GD functions are unavailable';
This confirms extension loading, not every optional codec. A build can load GD while lacking a format your application expects, so also inspect the reported capability list or test the specific operation in a controlled environment.
Troubleshoot a missing or nonfunctional GD extension
“Call to undefined function imagecreatetruecolor()”
This generally means the executing runtime has not loaded GD. Check the runtime’s configuration path, enable the extension using the method appropriate to the installation, restart the relevant process, and verify again. If CLI verification succeeds but the error persists in a web request, investigate the separate web-server PHP configuration.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Configure cannot find JPEG, PNG or zlib
Install the development package, not only the runtime library. Confirm that the compiler can locate headers and link files, then rerun configuration from a clean source-build directory when required by the build system. For PNG, check zlib as well as libpng. If multiple library versions are installed, inspect pkg-config paths and linker search paths so the headers and libraries come from the same intended installation.
A format works in one environment but not another
Format support is compiled into each PHP build. Compare the PHP versions, GD capability reports and configure options of the two environments. A WebP or AVIF image can fail on a build where GD is present but that optional switch or library was omitted.
GD disappeared after a PHP upgrade
A new PHP major or minor installation can use a new extension directory and a new configuration file. Reinstall or re-enable the GD package or DLL for the new runtime, then restart its service. On Windows, recheck whether the new release uses php_gd.dll; legacy documentation mentioning php_gd2.dll applies only before PHP 8.0.
Source build succeeds but PNG handling is unreliable
Recheck the libpng consistency requirement. The libpng headers used during compilation must correspond to the version linked with GD. Remove stale build artifacts and rebuild after correcting the library paths so the resulting binary is linked against one coherent libpng installation.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteDecide which GD capabilities your application actually needs
Start with the image operations your code performs, then map them to build options. Enabling every possible format increases dependency and maintenance work without helping an application that only creates JPEG thumbnails.
- Basic raster work: enable GD with the required PNG and JPEG dependencies.
- WebP processing: add WebP support and verify it in the runtime capability report.
- AVIF processing: use PHP 8.1.0 or newer with the AVIF option and compatible development support.
- Legacy XPM images: add XPM support using the option name accepted by the PHP release.
- Text rendering: add FreeType support from PHP 7.4 onward and ensure
pkg-configcan locate FreeType.
Keep the PHP version, operating system, library versions and deployment runtime documented alongside the build. That record makes a later upgrade easier to reproduce and helps explain why two servers with “GD installed” may expose different image functions.
Quick Recap
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.

