I have this piece of code that calls a random image and sends it to another page. That page calls this script via an image link. What I am trying to figure out is how to make it specify an image width when the image is past my max width. I got this far then got completely lost.
<?php
$folder = '';
$exts = 'jpg jpeg png gif';
$files = array(); $i = -1;
if ('' == $folder) $folder = './';
$handle = opendir($folder);
$exts = explode(' ', $exts);
while (false !== ($file = readdir($handle))) {
foreach($exts as $ext) {
if (preg_match('/\.'.$ext.'$/i', $file, $test)) {
$files[] = $file;
++$i;
}
}
}
closedir($handle);
mt_srand((double)microtime()*1000000);
$rand = mt_rand(0, $i);
$image =($folder.$files[$rand]);
if (file_exists($image))
{
list($width) = getimagesize($image);
$maxWidth = 150;
if ($width > $maxWidth)
{
header('Location: '.$folder.$files[$rand]); // Voila!;
}
else
{
header('Location: '.$folder.$files[$rand]); // Voila!
}
}
?>