Imagemagick text on gradient background

I’m really close but not quite there. I’m trying to have some text on a gradient background. This is my code:

$text = 'testing';
$width = 1000;
$height = 1000;

$textBackground = new ImagickPixel('transparent');
$textColor = new ImagickPixel('#000');

$gradient = new Imagick();
$gradient->newPseudoImage($width, $height, 'gradient:blue-red');

$image = new Imagick();
$image->newImage($width, $height, $textBackground);


$draw = new ImagickDraw();
$draw->setFontSize( 10 );
$draw->setGravity(Imagick::GRAVITY_CENTER );

$image->annotateImage($draw, 0, 0, 0, $text);

$gradient->compositeImage($image, Imagick::COMPOSITE_MATHEMATICS, 0, 0);

header('Content-type: image/png');
echo $image;

The end result is I get a 20×20 transparent image, which doesn’t seem to show the gradient or the text. I’m not sure where this code is going wrong

Source: stackoverflow-php