0

我正在尝试使用 php gd 函数翻转图像imageflip()。我安装了GD。我在 Windows 上使用 WAMP 和 codeigniter。(并且在 wamp 上实现 imagemagick 有点困难——所以我不想这样做)。imageflip() 应该像我看到的那样工作。我正在使用 PHP 版本 5.4.16。

也许我错过了一些东西......

来自phpinfo()

gd

GD Support          enabled
GD Version          bundled (2.1.0 compatible)
FreeType Support    enabled
FreeType Linkage    with freetype
FreeType Version    2.4.10
GIF Read Support    enabled
GIF Create Support  enabled
JPEG Support        enabled
libJPEG Version     8
PNG Support         enabled
libPNG Version      1.2.50
WBMP Support        enabled
XPM Support         enabled 
libXpm Version      30411
XBM Support         enabled

Directive               Local Value     Master Value
gd.jpeg_ignore_ warning     0               0

我有这个代码:

foreach($products_settings as &$ps) {                
    $filename = $_SERVER['DOCUMENT_ROOT'] . $ps['product_file'];                
    $source_image = imagecreatefromjpeg($filename);  

    //Put source image-resource into array
    $ps['source_image'] = $source_image;
}

它有效..

当我使用imagerotate()它时,它也可以工作......

foreach($products_settings as &$ps) {                
    $filename = $_SERVER['DOCUMENT_ROOT'] . $ps['product_file'];                
    $source_image = imagecreatefromjpeg($filename);  

    //rotate image
    $angle = $ps['product_angle'];
    if (intval($angle) <> 0) {
        $source_image = imagerotate($source_image, 360-$angle, imageColorAllocateAlpha($source_image, 255, 255, 255, 127));
    }

    //Put source image-resource into array
    $ps['source_image'] = $source_image;
}

...但是当我使用 imageflip ( http://php.net/manual/en/function.imageflip.php )

foreach($products_settings as &$ps) {                
    $filename = $_SERVER['DOCUMENT_ROOT'] . $ps['product_file'];                
    $source_image = imagecreatefromjpeg($filename);  
    imageflip($source_image, IMG_FLIP_BOTH);   //code execution stops here

    //Put source image-resource into array
    $ps['source_image'] = $source_image;
}  

然后imageflip()使代码停止(如果我在未记录后的行中添加日志消息)。我不知道为什么?那会是什么原因呢?我在 codeigniter/php/apache 的错误日志中看不到任何内容。手册说该函数在失败时将返回 false,但我知道图像是正确的,因为我将其他 gd 函数用于与其他 gd 函数(如等)相同imagerotateimageColorAllocateAlpha图像

我也试过这个:

try {
    imageflip($source_image, IMG_FLIP_BOTH); 
}
catch (Exception $e) {
    log_message('DEBUG', 'img err' . $e->__toString());
}

但是什么都没有记录...

如何调试这个?

4

1 回答 1

1

imageflipPHP 5.4.16 版中没有这个功能。安装 PHP 5.5 即可使用该功能。

如果您无法安装 PHP 5.5 并且需要使用 GD 翻转图像,您还可以使用一些适用于旧 PHP 版本的代码,我为您搜索了一下:

对于一些小问题,我并不完全同意代码,但它实际上很好地展示了如何做到这一点。

于 2013-09-01T09:30:19.790 回答