TexasMd91 Posted April 14, 2009 Share Posted April 14, 2009 I am using a script my friend made to randomly select an image from the directory and output it, I want to change it so that I can specify the minimum and maximum size (in pixel) that the image can be, so if a forum has rules on size I can still use the dynamic sig. I have changed the code a bit to bring in the size variable, but I am stumped on where to go from there ???. x0 = x min x1 = x max y0 = y min y1 = y max I need to have it so that if the value is set to 0, then it will disable. so if I have x0=0 and x1=250 it would be any graphic less then 250px wide. Or if I have x0=250 and x1=0 then it would be any graphic bigger then 250. <?php function sanitizeInput($string) { return ereg_replace("[^0-9]", "", $string); } $x0 = sanitizeInput($_GET['x0']); $y0 = sanitizeInput($_GET['y0']); $x1 = sanitizeInput($_GET['x1']); $y1 = sanitizeInput($_GET['y1']); $extList = array(); $extList['gif'] = 'image/gif'; $extList['jpg'] = 'image/jpeg'; $extList['png'] = 'image/png'; $img = null; $fileList = array(); $handle = opendir('./'); while ( false !== ( $file = readdir($handle) ) ) { $file_info = pathinfo($file); if (isset($extList[strtolower($file_info['extension'])])) { $fileList[] = $file; } } closedir($handle); $imageNumber = time() % count($fileList); $img = './' . $fileList[$imageNumber]; if ($img!=null) { $imageInfo = pathinfo($img); $contentType = 'Content-type: '.$extList[ $imageInfo['extension'] ]; header ($contentType); readfile($img); } ?> Link to comment https://forums.phpfreaks.com/topic/154122-checking-an-image-for-its-size/ Share on other sites More sharing options...
MasterACE14 Posted April 14, 2009 Share Posted April 14, 2009 use http://au2.php.net/manual/en/function.getimagesize.php Link to comment https://forums.phpfreaks.com/topic/154122-checking-an-image-for-its-size/#findComment-810234 Share on other sites More sharing options...
TexasMd91 Posted April 15, 2009 Author Share Posted April 15, 2009 I figured out how to do it. <?php function sanitizeInput($string) { return ereg_replace("[^0-9]", "", $string); } $x0 = sanitizeInput($_GET['x0']); $y0 = sanitizeInput($_GET['y0']); $x1 = sanitizeInput($_GET['x1']); $y1 = sanitizeInput($_GET['y1']); $extList = array();$extList['gif'] = 'image/gif';$extList['jpg'] = 'image/jpeg'; $extList['png'] = 'image/png'; $img = null; $fileList = array(); $handle = opendir('./'); while ( false !== ( $file = readdir($handle) ) ) { $file_info = pathinfo($file); if (isset($extList[strtolower($file_info['extension'])])) { $imgSize = getimagesize($file); if ((($x0 <= $imgSize[0]) || ($x0 == 0)) && (($y0 <= $imgSize[1]) || ($xy == 0)) && (($x1 >= $imgSize[0]) || ($x1 == 0)) && (($y1 >= $imgSize[1]) || ($y1 == 0))) { $fileList[] = $file; } } } closedir($handle); $imageNumber = time() % count($fileList); $img = './' . $fileList[$imageNumber]; if ($img!=null) { $imageInfo = pathinfo($img); $contentType = 'Content-type: '.$extList[ $imageInfo['extension'] ]; header ($contentType); readfile($img); } ?> I actually knew about the function getimagesize, I just didn't know how to efficiently apply it to the code. The first time I did it I actually had it check the size of the image after it randomly selected it; if it wasn't correct it would just select a random one again. Problem is then some 1 could specify $_GETs that would make it false and there wasn't a way to stop the script until it reached the mass exe time. But then I figured out that I need to trim out the wrong sized ones when ever I make the array of images, that way there is no reason to randomize it a second time. Now I can provide error messages when necessary And for the people that want to see it working. http://dvclan.org/signature/0/0/0/0.png first two 0s are minimum, last 2 are maximum. Link to comment https://forums.phpfreaks.com/topic/154122-checking-an-image-for-its-size/#findComment-810346 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.