dourangdz750379 2014-05-14 15:17
浏览 93
已采纳

PHP Imagick的fxImage根本不起作用

I have a simple convert's imagemagicks command-line which I want to mimic with PHP's Imagick class:

convert \( "image1.jpg" \) \
        \( -size 1x256 gradient:white-black \
           -rotate 90 \
           -fx "floor(u*10+0.5)/10" \
        \) \
        "temp1.jpg"`

That line outputs 2 images: temp1-0.jpg which is just a copy of image1.jpg and temp1-1.jpg which is this one: temp1 As you can see it's a simple gradient image with an effect that makes the gradient not that smooth. And that works perfectly with the command-line imagemagick.

Although when I try to mimic that line with PHP, it does everything correct but the -fx part. The code is the following:

$canvas = new Imagick();
$canvas->newImage(1, 256, "white", "jpg");

$gradient = new Imagick();
$gradient->newPseudoImage(1, 256, "gradient:white-black");
$canvas->compositeImage( $gradient, imagick::COMPOSITE_OVER, 0, 0 );
$canvas->rotateImage(new ImagickPixel(), 90);
$canvas->fxImage("floor(s*10+0.5)/10");

header( "Content-Type: image/jpg" );
echo $canvas;

Like I said, it doesn't reproduce the fx part but rather a normal white-to-black gradient.

I'm new to Imagemagick but I've tried to apply a much simpler effect with that function u+10 but still the effect won't be seen. Am I missing something to make fxImage() work properly? Is there a workaround for an effect like that?

  • 写回答

1条回答 默认 最新

  • dovhpmnm31216 2014-05-15 02:19
    关注

    It looks like it's a bug in the Imagick library - The image is actually available, but as the return value of the function.

    $canvas = new Imagick();
    $canvas->newImage(1, 256, "white", "jpg");
    
    $gradient = new Imagick();
    $gradient->newPseudoImage(1, 256, "gradient:white-black");
    $canvas->compositeImage( $gradient, imagick::COMPOSITE_OVER, 0, 0 );
    $canvas->rotateImage(new ImagickPixel(), 90);
    $fxImage = $canvas->fxImage("floor(s*10+0.5)/10");
    
    $fxImage->setImageFormat('jpg');
    header( "Content-Type: image/jpg" );
    echo $fxImage;
    

    Produces an image with a stepped gradient.

    I've opened an issue for this on the Imagick github page.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!