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.

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

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?