views:

1666

answers:

3

Hey All,

What is causing this error?

Fatal error: Call to undefined function imagefilter() in /var/www/polaroid.php on line 5
  1 <?PHP
  2   $img_addr = $_GET['image_address'];
  3   $img = imagecreatefromjpeg($img_addr);
  4
      /* everything works as expected without this line */
  5   imagefilter($img, IMG_FILTER_GRAYSCALE);  
  6
  7   if ($img)
  8   {
        /* I moved the header function here so I can see errors in the browser. 
           If I leave it at the top of the file, the browser expects an image 
           and doesn't print the error messages. */
  9     header('Content-type: image/jpeg');
 10     imagejpeg($img);
 11   }
 12 ?>
 13

This is the URL I use:

http://localhost/polaroid.php?image_address=http://mattnelsoninfo.files.wordpress.com/2008/04/ceiling_cat1.jpg

NOTE: gd is listed in the output from phpinfo().

EDIT: I'm using PHP Version 5.2.6-2ubuntu4.1

Another EDIT:

phpinfo() yields this in the gd section

gd
GD Support  enabled
GD Version  2.0 or higher
FreeType Support    enabled
FreeType Linkage    with freetype
FreeType Version    2.3.7
T1Lib Support   enabled
GIF Read Support    enabled
GIF Create Support  enabled
JPG Support     enabled
PNG Support     enabled
WBMP Support    enabled

Thanks!

+2  A: 

What version of PHP are you using? It looks like imagefilter is a PHP5 function ... http://us3.php.net/manual/en/function.imagefilter.php

EDIT: Your code works on my version of PHP. For reference, here's my phpinfo:

gd
GD Support  enabled
**GD Version    bundled (2.0.34 compatible)**
FreeType Support    enabled
FreeType Linkage    with freetype
FreeType Version    2.1.9
T1Lib Support   enabled
GIF Read Support    enabled
GIF Create Support  enabled
JPG Support     enabled
PNG Support     enabled
WBMP Support    enabled
XBM Support     enabled

You might want to make sure that the GD Version is bundled. I've seen installations that say GD Support is enabled but not bundled. Not sure if that makes a difference though.

bryan
PHP Version 5.2.6-2ubuntu4.1
ThomasGHenry
So I'm assuming calling function_exists('imagefilter') returns false, correct?
bryan
Correct. Thanks for that though. I didn't know about function_exists()
ThomasGHenry
Can you show the gd section of your phpinfo()? Do you see "GD Version bundled (2.0.34 compatible)"? I know some people only see "GD Support - enabled" but they don't have the line which reads that the version is bundled.
bryan
wilco. please stand by....
ThomasGHenry
not bundled! we may be onto something... any idea how to change this?
ThomasGHenry
Not sure, but in the notes for on php.net for imagefilter, it says " Note: This function is only available if PHP is compiled with the bundled version of the GD library."So I do think that's the problem; it must be bundled. Maybe try a new installation? Sorry, not sure what else you can do.
bryan
bryan
Thanks! yeah, I've been reading about it. It's an intentional omission on the part of debian/ubuntu. gd is considered a fork of php... blah blah... sounds political and annoying. I'll have to compile php from source. :\
ThomasGHenry
https://bugs.launchpad.net/ubuntu/+source/php5/+bug/74647
ThomasGHenry
Makes sense. What a pain. -___-Good luck!
bryan
A: 

You are using PHP 5 on that machine? According to the manual that function is only available on PHP 5 (and higher): http://www.php.net/manual/en/function.imagefilter.php

Energiequant
PHP Version 5.2.6-2ubuntu4.1
ThomasGHenry
A: 

imagefilter seems to be available only if PHP is compiled agains the bundled GD library which in your case it's not (that's the difference between the bundled and enabled). Since you're using Ubuntu the version of php that you find in the repository does not have GD bundled.

Victor