Equivalent of ImageMagick gradient for php Imagick

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
Defacta
Posts: 9
Joined: 2017-04-19T03:48:21-07:00
Authentication code: 1151

Equivalent of ImageMagick gradient for php Imagick

Post by Defacta » 2017-04-20T11:02:21-07:00

Hello,

I looked for the equivalent of gradient for Imagick at http://php.net/manual/en/class.imagickpixel.php and at http://php.net/manual/en/class.imagick.php with no success.

What is the equivalent of

Code: Select all

convert -size 128x128 gradient:"rgba(255,0,0,0)-rgba(255,0,0,1)" 1.png
for php Imagick?

And at a general level, how to find the equivalent of an ImageMagick feature for php Imagick?

Many thanks.

snibgo
Posts: 8654
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Equivalent of ImageMagick gradient for php Imagick

Post by snibgo » 2017-04-20T11:22:14-07:00

As the question is about IMagick, I'm moving it to the IMagick forum.

A search for "gradient" in the IMagick forum shows answers, such as viewtopic.php?f=18&t=29903&p=134571&hil ... nt#p134571
snibgo's IM pages: im.snibgo.com

Defacta
Posts: 9
Joined: 2017-04-19T03:48:21-07:00
Authentication code: 1151

Re: Equivalent of ImageMagick gradient for php Imagick

Post by Defacta » 2017-04-20T11:40:10-07:00

Oh, ok thanks.

It's working for:

Code: Select all

$imgLine->newPseudoImage(500, 500, 'gradient:#cbcbcb-#94938f');
But not for:

Code: Select all

$imgLine->newPseudoImage(500, 500, 'gradient:direction=east gradient:#cbcbcb-#94938f');
Same code with direction from https://www.imagemagick.org/script/gradient.php
I get the error message:
Uncaught exception 'ImagickException' with message 'unrecognized color `direction=east gradient:#cbcbcb'

So tried also "gradient:angle=90 gradient: #cbcbcb-#94938f" but with the same error message. Any idea how to make a gradient with a specific direction ?

Thanks,
Vincent.

My version of Imagick :
imagick module version 3.2.0RC1
And:
convert -version
Version: ImageMagick 6.9.3-10 Q16 x86 2016-05-04 http://www.imagemagick.org

snibgo
Posts: 8654
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Equivalent of ImageMagick gradient for php Imagick

Post by snibgo » 2017-04-20T11:52:08-07:00

At the command line, "gradient:direction" etc need "-define". I don't know the equivalent in IMagick.
snibgo's IM pages: im.snibgo.com

Bonzo
Posts: 2765
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Equivalent of ImageMagick gradient for php Imagick

Post by Bonzo » 2017-04-20T11:55:24-07:00

The angled gradient is probably not supported In Imagick - it only supports some of the imagemagick operators and options.

I would create the gradient image and then rotate it or use exec( ) with the command you have.

Defacta
Posts: 9
Joined: 2017-04-19T03:48:21-07:00
Authentication code: 1151

Re: Equivalent of ImageMagick gradient for php Imagick

Post by Defacta » 2017-04-20T12:34:27-07:00

Yes, by rotating it. Thanks for the help :)

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests