GRADIENT SHAPES

This is a script for making gradients using PHP with Image Magick from the command line. This script uses the -fx operator, which I do not understand but I have gotten these codes from Image Magick and have used them to make these images. For details on the fx codes you can go to the IM studio. The latest version of IM does make gradcircles using a radial command. However these codes will work without the latest version of IM.

The first exec in each of these scrips is what makes the gardient itself, but they are only white. The second exec command in each script is what adds the color.
CODESEXAMPLES
<?php
$IN="temp/gradCircle.gif";
exec ("/usr/bin/convert -size 100x100 xc:-fx 'xx=i/w-.5; yy=j/h-.5; rr=xx*xx+yy*yy; 1-rr*4' $IN");
$SHIFT="-size 1x2 gradient:yellow-black -fx 'v.p{0,0}*u+v.p{0,1}*(1-u)'";
exec ("/usr/bin/convert $IN $SHIFT circle.gif");
?>
GRAD CIRCLE
<?php
$IN="temp/gradArc.gif";
exec ("/usr/bin/convert -size 100x100 xc: -fx 'rr=hypot(i/w-.5, j/h-.5); 1-rr*1.42' $IN");
$SHIFT="-size 1x2 gradient:yellow-black -fx 'v.p{0,0}*u+v.p{0,1}*(1-u)' -virtual-pixel black -distort Arc 90 -trim +repage";
exec ("/usr/bin/convert $IN $SHIFT arc.gif");
?>
GRAD ARC
<?php
$IN="temp/gradRoll.gif";
exec ("/usr/bin/convert -size 100x100 xc: -fx 'rr=hypot(i/w-.5, j/h-.5); 1-rr*1.42' $IN");
$SHIFT="-size 1x2 gradient:yellow-black -fx 'v.p{0,0}*u+v.p{0,1}*(1-u)' -roll +50+50";
exec ("/usr/bin/convert $IN $SHIFT roll.gif");
?>
GRAD ROLL
Same Script as the roll example with the colors switched
<?php
$IN="temp/gradDiamond.gif";
exec ("/usr/bin/convert -size 100x100 xc: -fx 'rr=hypot(i/w-.5, j/h-.5); 1-rr*1.42' $IN");
$SHIFT="-size 1x2 gradient:black-yellow -fx 'v.p{0,0}*u+v.p{0,1}*(1-u)' -roll +50+50";
exec ("/usr/bin/convert $IN $SHIFT diamond.gif");
?>
GRAD DIAMOND
Just reverse grad roll colors
<?php
$IN="temp/gradSquare.gif";
exec ("/usr/bin/convert -size 100x100 xc: -fx '(1-(2*i/w-1)^4)*(1-(2*j/h-1)^4)' $IN");
exec ("/usr/bin/convert $IN -size 1x2 gradient:yellow-black -fx 'v.p{0,0}*u+v.p{0,1}*(1-u)' square.gif");
?>
GRAD SQUARE
<?php
$IN="gradVTube.gif";
exec ("/usr/bin/convert -size 100x100 xc:-fx 'cos(pi*(i/w-.5))' -separate -rotate 90 $IN");
exec ("/usr/bin/convert $IN -size 1x2 gradient:yellow-black -fx 'v.p{0,0}*u+v.p{0,1}*(1-u)' Vtube.gif");
?>
GRAD TUBE VERT
<?php
$IN="gradHTube.gif";
exec ("/usr/bin/convert -size 100x100 xc:-fx 'cos(pi*(i/w-.5))' -separate -rotate 90 $IN");
exec ("/usr/bin/convert $IN -size 1x2 gradient:yellow-black -fx 'v.p{0,0}*u+v.p{0,1}*(1-u)' Htube.gif");
?>
GRAD TUBE HORZ
<?php
$IN="gradHorz.gif";
exec ("/usr/bin/convert -size 100x100 xc: -fx 'sc=.15;
(i/w-.5)/(1+sc*cos(j*pi*2/h)-sc)+.5' -rotate 90 $IN");
exec ("/usr/bin/convert $IN -size 1x2 gradient:yellow-black -fx 'v.p{0,0}*u+v.p{0,1}*(1-u)' horizontal.gif");
?>
GRAD HORIZONTAL
<?php
$IN="gradVert.gif";
exec ("/usr/bin/convert -size 100x100 xc: -fx 'sc=.15;
(i/w-.5)/(1+sc*cos(j*pi*2/h)-sc)+.5' $IN");
exec ("/usr/bin/convert $IN -size 1x2 gradient:yellow-black -fx 'v.p{0,0}*u+v.p{0,1}*(1-u)' vertical.gif");
?>
GRAD VERTICLE
<?php
$IN="gradTriangle.gif";
exec ("/usr/bin/convert -size 100x100 xc: -fx 'rr=hypot(i/w-.5, j/h-.5);
1-rr*1.42' -background black -wave -28x200 -crop 100x100+0+0 +repage $IN");
$SHIFT="-size 1x2 gradient:yellow-black -fx 'v.p{0,0}*u+v.p{0,1}*(1-u)'";
exec ("/usr/bin/convert $IN $SHIFT triangle.gif");
?>
GRAD TRIANGLE
<?php
$IN="gradSlats.gif";
exec ("/usr/bin/convert -size 100x100 gradient: \( +clone +clone +clone +clone \) -background black -compose Add -flatten $IN");
$SHIFT="-size 1x2 gradient:yellow-black -fx 'v.p{0,0}*u+v.p{0,1}*(1-u)'";
exec ("/usr/bin/convert $IN $SHIFT slats.gif");
?>
GRAD SLATS
<?php
$IN="gradDiagSlat.gif";
exec ("/usr/bin/convert -size 100x100 gradient: \( gradient: -rotate -90 \) \( -clone 0--1 -clone 0--1 \) -background gray50 -compose Add -flatten $IN");
$SHIFT="-size 1x2 gradient:yellow-black -fx 'v.p{0,0}*u+v.p{0,1}*(1-u)'";
exec ("/usr/bin/convert $IN $SHIFT diagonal.gif");
?>
GRAD DIAGONAL
<?php
$IN="temp/gradCorner.gif";
exec ("/usr/bin/convert -size 100x100 xc: -channel G -fx '.5 - atan2(j-h/2,w/2-i)/pi/2' -separate $IN");
exec ("/usr/bin/convert $IN -size 1x2 gradient:yellow-black -fx 'v.p{0,0}*u+v.p{0,1}*(1-u)' corner.gif");
?>
GRAD CORNER


Below are a zip of a sample gradient shape script plus a gradient shape form. You must create a directory called temp as all the images of the script will be output to the temp directory. There is also a text version of the form if you prefer that to the zip.

GRADSHAPE ZIP

GRADSHAPE TEXT