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 »

$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: 12666
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Create a diagonal gradient

Post by snibgo »

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: 26061
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Create a diagonal gradient

Post by fmw42 »

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 »

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: 12666
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Create a diagonal gradient

Post by snibgo »

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 »

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: 12666
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Create a diagonal gradient

Post by snibgo »

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 »

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 »

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 »

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

Post Reply