104

I’ve searched for this and the solutions provided in past questions are completely incomprehensible to me. Whenever I run functions like imagecreatefromjpeg, I get this:

Fatal error: Call to undefined function imagecreatefromjpeg() ...

I’m working on a new install of PHP; my last installation never had this problem. I don’t get what’s going on.

TRiG
  • 10,148
  • 7
  • 57
  • 107
UserIsCorrupt
  • 4,837
  • 15
  • 38
  • 41

15 Answers15

100

Install GD Library

Which OS you are using?

http://php.net/manual/en/image.installation.php

Windows http://www.dmxzone.com/go/5001/how-do-i-install-gd-in-windows/

Linux http://www.cyberciti.biz/faq/ubuntu-linux-install-or-add-php-gd-support-to-apache/

admoghal
  • 1,498
  • 1
  • 10
  • 5
  • 1
    Gah, the solution in that link worked fine. I've been fiddling with this forever and couldn't get it to work, didn't know it was that simple. Thank you for finding this! – UserIsCorrupt Nov 12 '12 at 04:34
77

In Ubuntu/Mint (Debian based)

$ sudo apt-get install php-gd
Pierre de LESPINAY
  • 44,700
  • 57
  • 210
  • 307
36

If you are like me and you are using one of the PHP Docker images as your base, you need to add the gd extension using different instructions then what's discussed above.

For the php:7.4.1-apache image you need to add in your Dockerfile:

RUN apt-get update && \
    apt-get install -y zlib1g-dev libpng-dev libjpeg-dev

RUN docker-php-ext-configure gd --with-jpeg && \
    docker-php-ext-install gd

These dev packages are needed for compilation of the GD php extension. For me this resulted in activation of GD with PNG and JPEG support in PHP.

Paul
  • 1,337
  • 11
  • 11
23

You can still get Fatal error: Call to undefined function imagecreatefromjpeg() even if GD is installed.

The solution is to install/enable jped lib:

On Ubuntu:

    apt-get install libjpeg-dev
    apt-get install libfreetype6-dev

On CentOS:

    yum install libjpeg-devel
    yum install freetype-devel

If compiling from source add --with-jpeg-dir --with-freetype-dir or --with-jpeg-dir=/usr --with-freetype-dir=/usr.

For more details check https://www.tectut.com/2015/10/solved-call-to-undefined-function-imagecreatefromjpeg/

Mugoma J. Okomba
  • 3,185
  • 1
  • 26
  • 37
21

You must enable the library GD2.

Find your (proper) php.ini file

Find the line: ;extension=php_gd2.dll and remove the semicolon in the front.

The line should look like this:

extension=php_gd2.dll

Then restart apache and you should be good to go.

Commander
  • 1,322
  • 2
  • 13
  • 29
  • 2
    Just a note for anyone looking at this since php.ini is a big file. This line is under the `Dynamic Extensions` category (roughly middle of the document) – Eric F Nov 22 '19 at 15:21
  • 2
    Just a note for anyone using PHP 8 or greater it will be `extension=gd` instead. – gotnull Sep 28 '21 at 05:18
14
sudo apt-get install phpx.x-gd 
sudo service apache2 restart

x.x is the versión php.

CodeNoob
  • 345
  • 4
  • 17
12

For php 7 on Ubuntu:

sudo apt-get install php7.0-gd

Positonic
  • 9,151
  • 14
  • 57
  • 84
9

After installing php5-gd apache restart is needed.

Piotr Olaszewski
  • 6,017
  • 5
  • 38
  • 65
8

I spent so much time trying to figure this out on Windows after installing PHP Version 8.0.11.

I created this phpinfo.php file to check whether GD was loaded:

<?php
if (extension_loaded('gd')) {
  print 'gd loaded';
} else {
  print 'gd NOT loaded';
}

phpinfo(); ?>

If it returns gd NOT loaded then ensure that in your php.ini file you have the following unchecked:

; - Many DLL files are located in the extensions/ (PHP 4) or ext/ (PHP 5+)
;   extension folders as well as the separate PECL DLL download (PHP 5+).
;   Be sure to appropriately set the extension_dir directive.
;
extension=gd

Further down they'll be a section for extension_dir on Windows you need to uncheck the following:

; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
;extension_dir = "./"
; On windows:
extension_dir = "ext"

You should now see gd loaded when running the phpinfo.php file and any function calls (like imagecreatefromjpeg()) should now work as intended.

gotnull
  • 26,454
  • 22
  • 137
  • 203
7

In CentOS, RedHat, etc. use below command. don't forget to restart the Apache. Because the PHP module has to be loaded.

yum -y install php-gd
service httpd restart
Muthukumar Anbalagan
  • 1,138
  • 12
  • 15
3

As mentioned before, you might need GD library installed.

On a shell, check your php version first:
php -v

Then install accordingly. In my system (Linux-Ubuntu) it's php version 7.0:
sudo apt-get install php7.0-gd

Restart your webserver:
systemctl restart apache2

You should now have GD library installed and enabled.

arakno
  • 428
  • 3
  • 6
1

after
systemctl restart php-fpm
the Gd library works.

1

I am replying in 2022, anyone still facing this problem may my answer helpful. If your PHP version,n is 8+ you can add the below line to your php.ini file which is located in the PHP folder.

extension=php_gd.dll
Pisumathu
  • 411
  • 1
  • 5
  • 10
1

uncomment "extension=gd" in the php ini file

Md Rehan
  • 309
  • 2
  • 8
0

I have managed to fix this problem by doing the following:

  1. Find out which version of php you are running by typing this into the terminal:

php --version

My PHP version was 7.4:

PHP 7.4.3 (cli) (built: Nov  2 2022 09:53:44) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies
  1. Install php-7.4-gd

sudo apt-get install php7.4-gd

  1. Restart Apache

systemctl restart apache2

George Chalhoub
  • 14,968
  • 3
  • 38
  • 61