18

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.

k to the z
  • 3,217
  • 2
  • 27
  • 41
John Stant
  • 181
  • 1
  • 1
  • 4
  • 3
    The error says that the function is not defined, so be sure you have the function defined in that file, or you have included a file where that function is defined. – Nobita Apr 22 '11 at 13:58

6 Answers6

17

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!

markus
  • 40,136
  • 23
  • 97
  • 142
  • I would say so, this wasn't set-up by me. I'm not as proficient with php. I assume it was working up to a certain point as there are hundreds of products already on the website. – John Stant Apr 22 '11 at 14:06
  • 3
    Programmers are always inheriting a vast wealth of legacy piles of...job security? – k to the z Apr 22 '11 at 14:07
  • Is there a quick fix for someone like me? I'm a front end developer, php isn't my strongest point! – John Stant Apr 22 '11 at 14:10
  • Update PHP is your quick fix... in case that's not breaking your app. Try it on your development and staging environment. – markus Apr 22 '11 at 14:11
  • @markus's updated answer: John needs to be prompted to look at his phpinfo() output to see his php version to see if you're right.\ – k to the z Apr 22 '11 at 14:13
  • @markus, imagecreatetruecolor: With PHP 4.2.x this behaviour is different in issuing a warning instead of an error. He could be throwing a warning with imagecreate and an error with the second function. – k to the z Apr 22 '11 at 14:16
  • I am running PHP Version 5.3.2-1ubuntu4.7 – John Stant Apr 22 '11 at 14:20
  • Sorry, if you scroll down the phpinfo output the configuration section lists out all the php extensions alphabetically. – k to the z Apr 22 '11 at 14:22
  • GD is all enabled. Version 2.0. Freetype version 2.3.11 – John Stant Apr 22 '11 at 14:26
  • wow. Alright. I upvoted the question since this has turned mystery. – k to the z Apr 22 '11 at 14:30
  • Thanks! Hopefully someone can help. – John Stant Apr 22 '11 at 14:32
  • @markus: I have just checked my phpinfo(). I can't find any flag in there. What exactly does this mean? – John Stant Apr 22 '11 at 14:36
  • How would this just have changed though? The client was able to add and edit products until one day it just stopped working without any of the code edited? Could someone clarify what my next steps should be? How do I compile --with-gd=shared with my php? Sorry for my lack of php knowledge – John Stant Apr 22 '11 at 14:48
  • @markus, I believe if his GD version says something like: bundled (2.0.34 compatible), that's the same as the --with-gd=shared flag – k to the z Apr 22 '11 at 14:49
  • OK, thanks but still quite confused. Could you give me a more in depth guide from start to finish? I would highly appreciate it. Where is the compile string? I'm mainly a web designer/front end developer. I know very little php. – John Stant Apr 22 '11 at 15:06
  • Well... that's really all there is to know. The question is, do you have shell access to the server and shouldn't you delegate this task to a sysadmin? – markus Apr 22 '11 at 15:07
  • Ahhh, if I were you I wouldn't post my phpinfo in public, delete that please or at least remove publi access soon again! – markus Apr 22 '11 at 15:09
  • @markus: Mainly put it there so you could have a look. It's now removed. I have been tasked with making design updates and front end amendments to the site but can't do so until this error is cleared up. I'm just a little confused on how to do this. Your post was a great help but I really don't know where to go from here. – John Stant Apr 22 '11 at 15:11
  • Do you have shell access to the server? – markus Apr 22 '11 at 15:13
  • I don't have 20 reputation. Only new here, have 6! – John Stant Apr 22 '11 at 15:17
  • Leave chat and re-enter, please. – markus Apr 22 '11 at 15:22
  • seems there is a lag... chat doesn't recognize your new rep yet. – markus Apr 22 '11 at 15:23
  • I gotta go, see you later or another day. If you can enter chat at one moment ask whoever is there. – markus Apr 22 '11 at 15:25
3

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!

RaggaMuffin-420
  • 1,762
  • 1
  • 10
  • 14
3

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.

Joel Handwell
  • 742
  • 1
  • 10
  • 18
2

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

Ololo
  • 1,087
  • 9
  • 16
0

This function is part of the GD library. The library may not be installed in your PHP environment.

Details how to include GD can be found here: http://www.php.net/manual/en/image.installation.php

SteAp
  • 11,853
  • 10
  • 53
  • 88
-1

That means you either spelled the imageantialias() function incorrectly or you haven't defined that function in your code or the third party code it belongs to wasn't included in your current document.

UPDATE: GD is installed. This is a mystery.

k to the z
  • 3,217
  • 2
  • 27
  • 41