Image in PHP with background of two colors

Hi,
Is it possible to create an image in php with background of two colors? For example top side with a color and the lower half of the image with another background color.

The imagecolorallocate() sets background with a single color.

I would guess you need to make the background first with two images of the different colours; save that then put on your top image.

The solution i found is to create the image with a fill color, imagefill(), then to draw a rectangle with another color in the lower half of the image; then to add text and other things.
Here is the code, if someone needs it:

<?php
// Create a 160x80 image
$width = 160;
$height = 80;
$im = imagecreatetruecolor($width, $height);

// sets background to red
$red = imagecolorallocate($im, 255, 0, 0);
imagefill($im, 0, 0, $red);

// sets and draw a white rectangle
$white = imagecolorallocate($im, 255, 255, 255);
imagefilledrectangle($im, 0, $height/2, $width, $width/2, $white);

// sets and adds a text
$text = 'CoursesWeb.net';
$text_color = imagecolorallocate($im, 0, 1, 255);
imagestring($im, 5, 12, $height/3, $text, $text_color);

// Display directly the image
header('Content-Type: image/png');
imagepng($im);