I currently have this snippet which spits out a random image
$imgDir = 'images/';
$images = glob($imagesDir . '*.{jpg}', GLOB_BRACE);
$randimg = $images[array_rand($images)];
but I want the image to be a certain width (600px), rather then warping images by using CSS is there a way the image width can be checked using PHP incorporating the code snippet above?
Yes, you can go through each individual file and check its size with
getimagesize.That’s of course a very expensive operation to do every time. Instead, do this once and make the size part of the filename (e.g.
foobar_500.jpg) andglobfor that, or use a database to organize your images to begin with where you can save such metadata and query for it.