Jump to content

getting image sizes and ignoring some


real_illusions

Recommended Posts

Hi all,Is it possible to do this:Go through a folder of images, and only display a certain number (which is done thanks to a previous thread I made) but only display those images that are landscape?I see theres a getimagesize() function, would the best way be to compare the width's and height's, and add all those that have a width thats longer (higher number) than their height, and then randomise the array and display only a certain number of them?This is the random images script:

$images = glob("photos/folder/*");		$random = array_rand($images, 12);			foreach ($random as $n) {				//do_something_with($images[$n]);				echo "<img src=\"" . ($images[$n]) . "\" alt=\"\" />";			}

Link to comment
Share on other sites

I'm not sure how you would define a criteria for checking if a picture was landscape. I'm not sure what a common landscape ratio is, but for each image you are getting out of that folder, divide the width by the height and compare it against the ratio and evaluate it based on being =, </<=, >/>=, if it passes the test, assign that path to a final holder array. Once you've filtered out your images, I would just run the array through this function.http://php.net/manual/en/function.shuffle.php

Link to comment
Share on other sites

this is a slightly amended script i used to originally insert image details within a javascript array

$imgdir = '../images/';$filename=glob($imgdir."*.gif");   echo 'pathlength = '.strlen($imgdir).'";<br/>';$count=0;for($i=0;$i<count($filename);$i++){$size=getimagesize($filename[$i]);if($size[0] > $size[1]){echo 'imagearray['.$count.']="'.$filename[$i].'";<br/>';echo 'imgheight['.$i.']="'.$size[1].'";<br/>';echo 'imgwidth['.$i.']="'.$size[0].'";<br/><br/>';$count++;}}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...