imagecreatetruecolor() is undefined because the GD extension is missing
Fatal error: Uncaught Error: Call to undefined function imagecreatetruecolor()Short answer
All imagecreate* and imagecreatetruecolor functions come from the GD extension. The error means the PHP you are running has not loaded GD. Check with php -m, then install it: php-gd on Ubuntu, docker-php-ext-install gd in the official Docker image, or remove the semicolon from extension=gd in php.ini.
Fix it fast
1Find out which cause you have
Ask the same PHP that throws the error whether GD is loaded.
php -m | grep -i gd2Match what you see, then jump to its fix
- 1
php -m prints nothing for gd on a server installed with aptThe GD package is not installed (Ubuntu or Debian)Fix - 2
The error appears inside a container built from a php:8.x imageThe official Docker php image was built without GDFix - 3
The extension file exists, yet php -m does not list gd (typical on Windows)GD is built or shipped but switched off in php.iniFix
- 1
What does the error look like?
Fatal error: Uncaught Error: Call to undefined function imagecreatetruecolor()
Cause 1 of 3
The GD package is not installed (Ubuntu or Debian)
1Check
Ubuntu 24.04 ships GD as the php-gd package, which pulls in php8.3-gd.
apt list --installed 2>/dev/null | grep -i php8.3-gd2Fix
Install the package.
sudo apt install php-gd3Verify
The function should now exist.
php -r 'var_dump(function_exists("imagecreatetruecolor"));'Confirmed by packages.ubuntu.com
Cause 2 of 3
The official Docker php image was built without GD
1Check
The image does not install extension dependencies for you. GD needs libpng and libjpeg, and FreeType for fonts, installed by hand before the extension is built.
docker run --rm my-image php -m | grep -i gd2Fix
Install the libraries, configure GD with FreeType and JPEG support, and build it. This is the example in the image documentation.
RUN apt-get update && apt-get install -y \
libfreetype-dev \
libjpeg62-turbo-dev \
libpng-dev \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd3Verify
Rebuild the image and list modules again.
docker build -t my-image .
docker run --rm my-image php -m | grep -i gdConfirmed by raw.githubusercontent.com
Cause 3 of 3
GD is built or shipped but switched off in php.ini
1Check
The php.ini files shipped with PHP list gd as a commented line. It stays off until the semicolon is removed. extension_dir must also point at the folder that holds the extension DLLs.
php --ini
php -i | grep -i extension_dir2Fix
Open the php.ini that php --ini reports, remove the leading semicolon so the line reads extension=gd, and restart the web server or PHP process.
; before
;extension=gd
; after
extension=gd3Verify
Start a new shell and list modules.
php -m | findstr /i gdConfirmed by raw.githubusercontent.com
How do I stop it coming back?
- List needed extensions (ext-gd) in composer.json so a missing one is reported on install.
- Put the extension install lines in the Dockerfile so every rebuild has GD.
- After changing php.ini, confirm with php -m instead of assuming.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
- Spotless LaundryAn on-demand laundry app: Flutter on a Laravel back end, with Firebase for live updates.
Related fixes
Back end
Composer says the gd extension is missing on a Laravel project
composer install or composer update stops on a package that requires ext-gd
Composer refuses to install a package that requires ext-gd when the PHP binary running Composer has no GD extension.
4 causes, each with a fixBack end
PHP says curl_init() does not exist because an extension is missing
Fatal error: Call to undefined function mb_strlen()
The function belongs to an extension (curl, mbstring, xml and others) that the PHP process running your code has not loaded.
4 causes, each with a fixBack end
PHP cannot turn a hostname into an IP address
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed
This warning means the operating system could not resolve the hostname PHP was asked to connect to.
3 causes, each with a fixBack end
Apache returns 503 or 504 because PHP-FPM did not answer in time
Error dispatching request
Apache sent the request to PHP-FPM and gave up waiting.
3 causes, each with a fixBack end
AWS SDK for PHP cannot get credentials from the instance profile metadata server
Error retrieving credentials from the instance profile metadata server.
The SDK tries the EC2 instance metadata service when it has no valid credentials from anywhere earlier in its chain.
4 causes, each with a fixBack end
AWS SDK for PHP rejects requests: the signature is from the future
Signature not yet current: {date} is still later than {date}
AWS compares the timestamp in your signed request with its own clock.
2 causes, each with a fix