Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top