How can PHP be used to efficiently display and manipulate graphics on a website?

PHP can be used to efficiently display and manipulate graphics on a website by utilizing libraries such as GD or Imagick. These libraries provide functions for creating, editing, and displaying images in various formats. By using these libraries in conjunction with PHP, developers can easily generate dynamic images, thumbnails, or other graphical elements on their websites.

<?php
// Create a new image with GD library
$width = 200;
$height = 200;
$image = imagecreatetruecolor($width, $height);

// Set background color
$bg_color = imagecolorallocate($image, 255, 255, 255);
imagefill($image, 0, 0, $bg_color);

// Draw a red rectangle
$red = imagecolorallocate($image, 255, 0, 0);
imagefilledrectangle($image, 50, 50, 150, 150, $red);

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

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