Andrew's code for Drawing a Smiley Face
WORKER CODE FOLLOWS
<?php
// Set content type
header("Content-Type: image/png");
// Image size
$width = 300;
$height = 300;
// Create image
$image = imagecreatetruecolor($width, $height);
// Colors
$yellow = imagecolorallocate($image, 255, 205, 0);
$black = imagecolorallocate($image, 0, 0, 0);
$white = imagecolorallocate($image, 255, 255, 255);
// Fill background
imagefill($image, 0, 0, $white);
// Draw face
imagefilledellipse($image, 150, 150, 250, 250, $yellow);
// Draw eyes
imagefilledellipse($image, 110, 120, 30, 40, $black); // Left eye
imagefilledellipse($image, 190, 120, 30, 40, $black); // Right eye
// Draw smile
imagefilledarc($image, 150, 180, 150, 100, 0, 180, $black, IMG_ARC_PIE);
// Left eyebrow coordinates
$leftEyebrow = [
95, 90, // top-left
115, 85, // top-right
120, 95, // bottom-right
90, 100 // bottom-left
];
// Right eyebrow coordinates
$rightEyebrow = [
185, 85, // top-left
205, 90, // top-right
210, 100, // bottom-right
180, 95 // bottom-left
];
// Draw the polygons
imagefilledpolygon($image, $leftEyebrow, 4, $black);
imagefilledpolygon($image, $rightEyebrow, 4, $black);
// Output image
imagepng($image);
// Clean up
imagedestroy($image);