首页 文章

调用未定义的函数imagerotate()

提问于
浏览
4

我想,我有一个奇怪的错误 .

致命错误:在第30行的/var/www/web/html/include/php/class/image.class.php中调用未定义的函数imagerotate()

LINE 30:

$im = imagerotate( $this->res, $degrees, $bkg );

根据the PHP documentationimagerotate() 应该是PHP 4以后的函数,我使用的是PHP 5 .

为什么不起作用?其他图像功能,如 imagecreatefromjpeg()imagejpeg() 工作正常 .

GD info from phpinfo():

GD支持 enabled
GD版 2.0 or higher
FreeType支持 enabled
FreeType Linkage with freetype
FreeType版本 2.3.7
T1Lib支持 enabled
GIF阅读支持 enabled
GIF创建支持 enabled
JPG支持 enabled
PNG支持 enabled
WBMP支持 enabled

3 回答

  • 2

    page中你清楚地说明了它

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

    其中一个comments

    此函数显然包含内存泄漏 . 因此,它被排除在Ubuntu附带的GD库之外(我也假设其他操作系统) . 所以,如果你正在运行Ubuntu并想知道为什么你得到“调用未定义的函数imagerotate()”,即使你看起来安装了正确的GD lib,这就是原因 . 请使用dragonflydevelopment dot com提供的替代品 . 它完美无缺(对于90度的角度) . 另一方面,其他一些GD图像函数(不幸的是,更有趣的图像函数)遇到了同样的问题,并且也被排除在Ubuntu发行版之外 .

    有关可能的解决方案,请查看here

    代码从http://www.php.net/manual/en/function.imagerotate.php#93151复制并修订

    if (!function_exists('imagerotate')) {
    
        /*
            Imagerotate replacement. ignore_transparent is work for png images
            Also, have some standard functions for 90, 180 and 270 degrees.
            Rotation is clockwise
        */
    
        function imagerotate_rotateX($x, $y, $theta) {
            return $x * cos($theta) - $y * sin($theta);
        }
    
        function imagerotate_rotateY($x, $y, $theta) {
            return $x * sin($theta) + $y * cos($theta);
        }
    
        function imagerotate($srcImg, $angle, $bgcolor = 0, $ignore_transparent = 0) {
            $srcw = imagesx($srcImg);
            $srch = imagesy($srcImg);
    
            //Normalize angle
            $angle %= 360;
            //Set rotate to clockwise
            $angle = -$angle;
    
            if ($angle == 0) {
                if ($ignore_transparent == 0) {
                    imagesavealpha($srcImg, true);
                }
                return $srcImg;
            }
    
            // Convert the angle to radians
            $theta = deg2rad($angle);
    
            //Standart case of rotate
            if ((abs($angle) == 90) || (abs($angle) == 270)) {
                $width = $srch;
                $height = $srcw;
                if (($angle == 90) || ($angle == -270)) {
                    $minX = 0;
                    $maxX = $width;
                    $minY = -$height+1;
                    $maxY = 1;
                } else if (($angle == -90) || ($angle == 270)) {
                    $minX = -$width+1;
                    $maxX = 1;
                    $minY = 0;
                    $maxY = $height;
                }
            } else if (abs($angle) === 180) {
                $width = $srcw;
                $height = $srch;
                $minX = -$width+1;
                $maxX = 1;
                $minY = -$height+1;
                $maxY = 1;
            } else {
                // Calculate the width of the destination image.
                $temp = array(
                    imagerotate_rotateX(0, 0, 0 - $theta),
                    imagerotate_rotateX($srcw, 0, 0 - $theta),
                    imagerotate_rotateX(0, $srch, 0 - $theta),
                    imagerotate_rotateX($srcw, $srch, 0 - $theta)
                );
                $minX = floor(min($temp));
                $maxX = ceil(max($temp));
                $width = $maxX - $minX;
    
                // Calculate the height of the destination image.
                $temp = array(
                    imagerotate_rotateY(0, 0, 0 - $theta),
                    imagerotate_rotateY($srcw, 0, 0 - $theta),
                    imagerotate_rotateY(0, $srch, 0 - $theta),
                    imagerotate_rotateY($srcw, $srch, 0 - $theta)
                );
                $minY = floor(min($temp));
                $maxY = ceil(max($temp));
                $height = $maxY - $minY;
            }
    
            $destimg = imagecreatetruecolor($width, $height);
            if ($ignore_transparent == 0) {
                imagefill($destimg, 0, 0, imagecolorallocatealpha($destimg, 255,255, 255, 127));
                imagesavealpha($destimg, true);
            }
    
            // sets all pixels in the new image
            for ($x = $minX; $x < $maxX; $x++) {
                for ($y = $minY; $y < $maxY; $y++) {
                    // fetch corresponding pixel from the source image
                    $srcX = round(imagerotate_rotateX($x, $y, $theta));
                    $srcY = round(imagerotate_rotateY($x, $y, $theta));
                    if ($srcX >= 0 && $srcX < $srcw && $srcY >= 0 && $srcY < $srch) {
                        $color = imagecolorat($srcImg, $srcX, $srcY);
                    } else {
                        $color = $bgcolor;
                    }
                    imagesetpixel($destimg, $x-$minX, $y-$minY, $color);
                }
            }
    
            return $destimg;
        }
    
    }
    
  • 8

    你有机会运行Ubuntu吗?然后this可能会解释您收到错误消息的原因 .

  • 1

    首先在脚本中添加一个if:

    if(!extension_loaded('gd'))
                 throw new Exception('GD extenstion not installed');
    

    如果它的工作检查您的GD信息:

    echo '<pre>';
    var_dump(gd_info());
    

    并检查是否支持jpeg(它应该在dg_info结果中) .

    如果一切正常并且仍然无效,请询问您的托管服务 .

    (错误说你使用的是非现有函数,cna你在使用它的地方设置一些代码吗?)

相关问题