0

是什么导致了这个错误?

致命错误:在第 5 行的 /var/www/polaroid.php 中调用未定义的函数 imagefilter()
  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

这是我使用的网址:

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

注意:gd 列在 phpinfo() 的输出中。

编辑:我正在使用 PHP 版本 5.2.6-2ubuntu4.1

另一个编辑:

phpinfo() 在 gd 部分产生这个

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 

谢谢!

4

4 回答 4

3

imagefilter 似乎只有在 PHP 被编译为捆绑的 GD 库时才可用,在您的情况下它不是(这是捆绑和启用之间的区别)。由于您使用的是 Ubuntu,因此您在存储库中找到的 php 版本没有捆绑 GD。

于 2010-02-07T20:22:32.607 回答
2

您使用的是什么版本的 PHP?看起来 imagefilter 是一个 PHP5 函数... http://us3.php.net/manual/en/function.imagefilter.php

编辑:您的代码适用于我的 PHP 版本。作为参考,这是我的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

您可能需要确保捆绑了 GD 版本。我看到安装说启用了 GD 支持但未捆绑。不确定这是否会有所作为。

于 2009-02-18T23:41:41.150 回答
1

http://www.php.net/manual/en/function.imagefilter.php有一个通知:

注意:此功能仅在 PHP 与 GD 库的捆绑版本编译时可用。

于 2011-01-07T15:43:41.160 回答
0

就像 2016 年的更新一样,PHP 5.3 允许使用外部 GD,但由于某种原因,这在 lucid/precise 中不起作用。trusty,使用 PHP 5.5,除了 imageantialias 之外,所有这些图像功能都可以工作,来源https://bugs.launchpad.net/ubuntu/+source/php5/+bug/74647/comments/61(和以前的评论)。

于 2016-11-19T08:16:33.620 回答