Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

imageantialias call to undefined function error with GD installed

Tags:

function

php

gd

I need help with a php script. It is a CMS that has been implemented into a website. When trying to add a new product IMAGE or trying to edit current images, I am getting the following error:

Fatal error: Call to undefined function imageantialias() in /home/mounts/home/m/mclh/web/admin/library/functions.php on line 233

This is my code for that area:

   if ($tmpDest['extension'] == "gif" || $tmpDest['extension'] == "jpg")
    {
       $destFile  = substr_replace($destFile, 'jpg', -3);
       $dest      = imagecreatetruecolor($w, $h);
       imageantialias($dest, TRUE);
    } elseif ($tmpDest['extension'] == "png") {
       $dest = imagecreatetruecolor($w, $h);
       imageantialias($dest, TRUE);
    } else {
      return false;
    }

Line 233 is the 5th line down.

like image 252
John Stant Avatar asked Apr 22 '11 13:04

John Stant


4 Answers

UPDATE: It seems the function imageantialias() is only available if PHP is compiled with GD, so it is not enough to have the extension included via extension file.

From the PHP manual:

Note: This function is only available if PHP is compiled with the bundled version of the GD library.

Please check your phpinfo() and see, if you find the flag --with-gd=shared (or a similar flag, maybe just --with-gd) in there. If you can't find it, your PHP has to be recompiled with this flag.

In more details: PHP extensions can either be loaded by including a .dll (Windows) or .so (Unix) file via php.ini or they can be compiled with PHP. Compiling sounds scary and crazy but it is actually really easy. All you need to do (Unix) is:

  1. copy the compile string which is shown in your phpinfo()
  2. add the required new flag
  3. run
    • ./configure ... all the stuff from your phpinfo plus the new flag
    • make clean
    • make
    • make install
  4. look at your phpinfo() and smile :)

First answer (didn't turn out to be correct):

imageantialias() is a function of the PHP GD extension. Is GD installed and properly configured?

From your code it seems that GD is installed because imagecreatetruecolor() is also a GD function and seems to work. This leads to the conclusion that you're using a PHP version prior to 4.3.2, which doesn't support imageantialias().

Please look at your phpinfo() to see if my conclusions are correct. There you will see what version of PHP your are using and you will also see if GD is installed and working!

like image 191
markus Avatar answered Nov 18 '22 00:11

markus


It seems that the Debian / Ubuntu PHP doesn't bundle the GD library with it, some security reason. You have to recompile PHP, follow this helpful step by step guide on doing so with Debian / Ubuntu: http://www.maxiwebs.co.uk/gd-bundled/compilation.php

Open up a terminal. Become root by typing su and enter your root password when prompted.

Download some packages we'll need for the install. Type apt-get install build-essential debhelper fakeroot dpkg-dev mysql-server. When MySQL install asks for the root password, think of one, then keep it safe. Change your current directory to your source one. cd /usr/src.

Download the PHP 5 source code by typing apt-get source php5. We also need the PHP 5 dependencies. To download these, enter apt-get build-dep php5.

Go into the downloaded PHP directory. cd php5-XXXX. just press after you've typed php5- to complete the folder name.

Now we need to edit a config file to change it into the bundled version of GD. Type nano debian/rules.

Locate the line that says --with-gd=shared,/usr --enable-gd-native-ttf \ and change it to --with-gd=shared --enable-gd-native-ttf \ by removing ,/usr. (Press ctrl+w to find something, if you search for gd, it is near the second occurrence). To save the file, we need to press ctrl+x then press y and then enter.

Now we need to edit the MySQL setup file. Type nano debian/setup-mysql.sh. Note: If this file does not exist, don't worry, you can skip steps 10 and 11.

Find the line $mysqld > $datadir/run.log 2>&1 & and change it to $mysqld --user=root > $datadir/run.log 2>&1 & by adding --user=root to it. To save the file, we need to press ctrl+x then press y and then enter.

Now we've done setting up we now need to compile it. Type dpkg-buildpackage -rfakeroot, or if you're using Ubuntu 11.10, you should type dpkg-buildpackage -d, this will take some time.

When it's done, you should have a load of .deb files in the parent directory. Find the one starting with php5-gd.

Install it by double clicking on it, or from the terminal, type dpkg -i php5-gdXXXXXXX just press after you've typed php5-gd to complete the file name.

Now we need to stop updates from replacing your shiny new GD library with the regular non-bundled version by holding the package. Run the following command: apt-get install wajig. Say yes to the install.

After the install, enter the following: wajig hold php5-gd.

Congratulations! You now have the bundled version of the GD Library installed, now go and be creative with it!

like image 29
RaggaMuffin-420 Avatar answered Nov 18 '22 01:11

RaggaMuffin-420


According to PHP Manual's Changelog for PHP Version 7.2.0:

imageantialias() is now generally available. Formerly it was only available if PHP was compiled with the bundled version of the GD library.

So there are some options to fix this.

  • If you have PHP lower than version 7.2.0, update it to PHP version above 7.2.0.
  • If you are not able to or not allowed to update php, then compile php with ./configure script with --with-gd flag.
  • Or you can install php-gd bundled extension without recompiling PHP
like image 3
Joel Handwell Avatar answered Nov 18 '22 00:11

Joel Handwell


Here is workaround for your issue Just download the rpm, extract gd-bundled.so from here and replace original gd.so with it.

like image 2
Ololo Avatar answered Nov 18 '22 01:11

Ololo