How can one retrieve the width of an image in PHP?

To retrieve the width of an image in PHP, you can use the getimagesize() function, which returns an array containing the width and height of the image. You can then access the width value from the returned array.

// Path to the image file
$imagePath = 'path/to/your/image.jpg';

// Get the image size
$imageSize = getimagesize($imagePath);

// Retrieve the width from the image size array
$imageWidth = $imageSize[0];

// Output the width of the image
echo 'Width of the image: ' . $imageWidth;