Skip to content

Instantly share code, notes, and snippets.

@bobye
Created February 11, 2012 12:57
Show Gist options
  • Save bobye/1799296 to your computer and use it in GitHub Desktop.
Save bobye/1799296 to your computer and use it in GitHub Desktop.
Similarity based shape navigation v2
<?php
$imgdir = 'snapshot-repo/';
$allowed_types = array('jpg');
$dimg = opendir($imgdir);
while($imgfile = readdir($dimg))
{
if(in_array(strtolower(substr($imgfile,-3)),$allowed_types))
{
$a_img[] = $imgfile;
sort($a_img);
reset ($a_img);
}
}
$totimg = count($a_img); // total image number
if (isset($_GET['id'])){
$shape_id = $_GET['id'];
$array = explode(",",exec("sed -n '".$shape_id.",1p' ".$imgdir."rank.matrix"));
}
else {
$shape_id = 0;
$array = range(1, $totimg);
}
echo "<title>Click to Navigate!</title>";
echo "<table align='center'><tr>";
for($x=0; $x < $totimg; $x++)
{
// create rows of 10
if ($x != 0) {
echo '<td><a href="index.php?id='.$array[$x].'"><img src="'.$imgdir.$array[$x].'.jpg" /></a><br />';
} else {
echo '<td><a href="index.php?id='.$array[$x].'"><img src="'.$imgdir.$array[$x].'.jpg" border="1"/></a><br />';
}
echo '</td>';
//close the row if count / 4 = 0
if ($x % 10 == 9){
echo "</tr><tr>";
}
}
//add empty cells to table to handle not having 4 images on last row
$remainder = ($totimg % 4);
if ($remainder > 0 ) {
for ($x=0; $x<$remainder; $x++){
echo "<td>&nbsp;</td>";
}
}
//close table
echo "</tr></table>";
//echo random image
//echo $totimg.'<br />';
//$oneless = ($totimg - 1);
//$rand = rand(1, $oneless);
//echo '<img src="'.$a_img[$rand].'" /><br />';
//echo '<strong>'.$a_img[$rand].'</strong>';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment