Page 1 of 1
How to create multigradients with PHP Imagick?
Posted: 2014-01-07T10:48:12-07:00
by KorbinianMoser
Hi, I already found out how to create radial gradients with transparency in PHP Imagick:
Code: Select all
$gradient->newPseudoImage( $radius*2, $radius*2, "radial-gradient:white-transparent");
Is there a similar way to realize multigradients like shown on
http://www.fmwconcepts.com/imagemagick/ ... /index.php? Or, if there isn't, is there an effective way to use Fred's solution as-is within my PHP Imagick project, without writing a tmp-file and reopening it? My aim is, to start the (fully opaque) white not at the center, but at a certain radius.
Thanks for any help!

Re: How to create multigradients with PHP Imagick?
Posted: 2014-01-07T11:58:24-07:00
by fmw42
I doubt that Imagick has anything like my script. It is not maintained as far as I know any longer and has not even kept up with improvements in Imagemagick. My script can be called from PHP exec().
Re: How to create multigradients with PHP Imagick?
Posted: 2014-01-07T12:40:47-07:00
by KorbinianMoser
Hi Fred, thanks for your answer! Ah, now I see that what you did is not just an example calling existing ImageMagick commands, in fact you extended ImageMagick with a complex script. Well, of course then there can't be a PHP Imagick command for that

Re: How to create multigradients with PHP Imagick?
Posted: 2014-01-07T13:30:24-07:00
by KorbinianMoser
Here's my solution:
Code: Select all
$gradient = new ImagickDraw();
$gradient->setFillColor('white');
for( $i=0; $i<100; $i++)
{
$gr = $innerRadius + $outerRadius/100 * ($i+1);
$gradient->setFillOpacity((1-($i+1)/100)/15);
$gradient->circle( $pos[0], $pos[1], $pos[0]+$gr, $pos[1]+$gr);
}
I thought, the fill opacity should sum up to 1 with 100 overlying circles, if I would make it 1/100 - in fact it didn't. That's why I change it in the loop and modified the formula until the result suited my needs.
Re: How to create multigradients with PHP Imagick?
Posted: 2014-01-08T18:59:11-07:00
by DJ Mike
Append some gradients then arc distort them
Code: Select all
<?php
$file = "radialgrad.gif"; # name of output gif
$w = 200;
$h = 200;
### First make a rainbow line
# new imagick object
$img1 = new Imagick();
# some gradients
$img1->newPseudoImage( 10, 100, 'gradient:red-orange' );
$img1->newPseudoImage( 10, 100, 'gradient:orange-yellow' );
$img1->newPseudoImage( 10, 100, 'gradient:yellow-green' );
$img1->newPseudoImage( 10, 100, 'gradient:green-blue' );
$img1->newPseudoImage( 10, 100, 'gradient:blue-purple' );
$img1->newPseudoImage( 10, 100, 'gradient:purple-red' );
# go back to top of stack
$img1->resetIterator();
$line = $img1->appendImages(true);
$line->rotateImage(new ImagickPixel(), 90);
$line->scaleimage($w, $h, FALSE );
$line->distortImage( Imagick::DISTORTION_ARC, array( 361 ), TRUE );
# Write final image
$line->writeimages( "$file", TRUE);
header( "location:$file" );
exit;
?>
Animated version:
viewtopic.php?f=18&t=18448&p=70903#p70903
Re: How to create multigradients with PHP Imagick?
Posted: 2014-01-09T01:57:06-07:00
by KorbinianMoser
not, what I needed, but very nice

Re: How to create multigradients with PHP Imagick?
Posted: 2014-01-09T19:14:33-07:00
by DJ Mike
Do you need the colors concentric? Delete
$line->rotateImage(new ImagickPixel(), 90);
Re: How to create multigradients with PHP Imagick?
Posted: 2014-01-10T04:27:33-07:00
by KorbinianMoser
Hi DJ Mike, thank you very much! For anyone else reading this, here's how I made it work for my purpose:
Code: Select all
$gradient = 200;
$opaque = 100;
# new imagick object
$img1 = new Imagick();
# some gradients
$img1->newPseudoImage( 10, $gradient, 'gradient:transparent-white' );
$img1->newImage( 10, $opaque, 'white' );
# double height for concentric radial gradient
$img1->newImage( 10, $gradient+$opaque, 'white' );
# go back to top of stack
$img1->resetIterator();
$line = $img1->appendImages(true);
# image size and radial distortion
$line->scaleimage($gradient+$opaque, $gradient+$opaque, FALSE );
$line->distortImage( Imagick::DISTORTION_ARC, array( 361 ), TRUE );
# Show final image
$line->setImageFormat('PNG32');
header('Content-Type:image/png');
exit( $line);
Re: How to create multigradients with PHP Imagick?
Posted: 2014-01-10T05:57:33-07:00
by KorbinianMoser
Sadly I found no way to make this precise

So I better keep my draw-100-circles approach.