What are common challenges faced by PHP beginners when using gdlib to draw shapes?

Common challenges faced by PHP beginners when using gdlib to draw shapes include incorrect syntax for function calls, improper handling of image resources, and misunderstanding of coordinate systems. To address these issues, beginners should ensure they are using the correct function names, properly allocating and freeing image resources, and understanding the x and y coordinates when drawing shapes.

<?php
// Create a blank image with a white background
$width = 400;
$height = 200;
$image = imagecreatetruecolor($width, $height);
$white = imagecolorallocate($image, 255, 255, 255);
imagefill($image, 0, 0, $white);

// Draw a red rectangle on the image
$red = imagecolorallocate($image, 255, 0, 0);
$x1 = 50;
$y1 = 50;
$x2 = 150;
$y2 = 100;
imagerectangle($image, $x1, $y1, $x2, $y2, $red);

// Output the image
header('Content-type: image/png');
imagepng($image);

// Free up memory
imagedestroy($image);
?>