Create a diagonal gradient

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
mc_hendriks
Posts: 14
Joined: 2014-02-28T00:30:49-07:00
Authentication code: 6789

Create a diagonal gradient

Post by mc_hendriks » 2017-03-07T14:23:36-07:00

$img=Image::Magick->new();
$img->Set(size=>'500x500');
$img->Read('gradient:green-red');


Gives a box with a linear gradient from left to right, I would like a linear gradient from top-left to bottom right in the same box.
If I use a Rotate than the complete box gets rotated.

Any hints are appreciated, I'm stuck here and can't find any decent documentation on this subject,

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

Re: Create a diagonal gradient

Post by snibgo » 2017-03-07T14:31:43-07:00

What version of IM? If from 6.9.2-5 onwards, try the techniques shown in http://www.imagemagick.org/script/gradient.php
Or you can do this with SparseColor Bilinear, by setting three colours at three corners of your image.
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 21518
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Create a diagonal gradient

Post by fmw42 » 2017-03-07T17:18:27-07:00

try

ReadImage('gradient:green-red'); not Read('gradient:green-red');

see docs at http://www.imagemagick.org/script/perl-magick.php (example for example for creating a white canvas is similar)

mc_hendriks
Posts: 14
Joined: 2014-02-28T00:30:49-07:00
Authentication code: 6789

Re: Create a diagonal gradient

Post by mc_hendriks » 2017-03-08T00:44:26-07:00

I'm using version 6.6.9-7
IMHO: Aren't Read and ReadImage the same? They produce the same results.


I looked at http://www.imagemagick.org/script/gradient.php
but how can I use these settings from perlmagick? For example:

-define gradient:vector=x1,y1, x2,y2

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

Re: Create a diagonal gradient

Post by snibgo » 2017-03-08T09:29:39-07:00

I don't use Perl Magick, but the doc http://www.imagemagick.org/script/perl- ... -attribute says:
You can optionally add Image to any method name. For example, ReadImage() is an alias for method Read().
For "-define", have you tried something like:

Code: Select all

$img->Set(gradient:vector=>'x1,y1, x2,y2');
snibgo's IM pages: im.snibgo.com

mc_hendriks
Posts: 14
Joined: 2014-02-28T00:30:49-07:00
Authentication code: 6789

Re: Create a diagonal gradient

Post by mc_hendriks » 2017-03-09T03:29:24-07:00

After your reply I tried:

$img->Set("gradient:vector"=>"1,1 100,100");
$img->Set("gradient_vector"=>"1,1 100,100");
$img->Set(gradient_vector=>"1,1 100,100");

Before and after the $img->ReadImage('gradient:green-orange');
I also tried to put in in the ReadIMage itself, no luck so far.

:(

Any ideas left?

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

Re: Create a diagonal gradient

Post by snibgo » 2017-03-09T03:42:10-07:00

But you didn't try what I actually wrote? It would come before the read, and would be useless after it.
snibgo's IM pages: im.snibgo.com

mc_hendriks
Posts: 14
Joined: 2014-02-28T00:30:49-07:00
Authentication code: 6789

Re: Create a diagonal gradient

Post by mc_hendriks » 2017-03-09T03:48:31-07:00

Of course I did, but perl doesn't like: $img->Set(gradient:vector=>'x1,y1, x2,y2');
You are not allowed to use a : in a hash key whithout enclosing with ' or "

so either .. Set('gradient:vector'=> ... of gradient_vector

But still no luck.

mc_hendriks
Posts: 14
Joined: 2014-02-28T00:30:49-07:00
Authentication code: 6789

Re: Create a diagonal gradient

Post by mc_hendriks » 2017-03-09T03:49:55-07:00

of is or (sorry I'm dutch)

mc_hendriks
Posts: 14
Joined: 2014-02-28T00:30:49-07:00
Authentication code: 6789

Re: Create a diagonal gradient

Post by mc_hendriks » 2017-03-09T07:33:47-07:00

I did not read the version question correctly..
I'm first going to upgrade ImageMagick and than try again.

Post Reply