Last active
August 29, 2015 13:57
-
-
Save justinph/9509092 to your computer and use it in GitHub Desktop.
Very simple script to allow for cycling through of images in a directory. Useful for viewing a bunch of screenshots or mockups in a folder somewhere on a LAMP host.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// get all images in dir | |
$imgs = glob("*.{jpg,png,gif,jpeg,svg,mng,PNG,JPG,JPEG,GIF,SVG,MNG}", GLOB_BRACE); | |
sort($imgs); | |
if (count($imgs) > 0){ | |
$totalImgs = count($imgs); | |
} | |
if (!isset($_GET['i'])){ | |
$curIdx = 1; | |
} else { | |
$curIdx = intval($_GET['i']); | |
} | |
if ($curIdx < 1){ | |
$curIdx = 1; | |
} | |
$next = $curIdx + 1; | |
if ($next > $totalImgs){ | |
$next = 1; | |
} | |
$prev = $curIdx -1; | |
if ($prev < 1){ | |
$prev = $totalImgs; | |
} | |
$curImg = $imgs[$curIdx-1]; | |
$nextURL = $_SERVER['PHP_SELF']."?i=".$next; | |
$prevURL = $_SERVER['PHP_SELF']."?i=".$prev; | |
$nextUrl = 0; | |
?><!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> | |
<title>Image <?php echo $curIdx;?> of <?php echo $totalImgs; ?></title> | |
<style type="text/css"> | |
body | |
{ | |
text-align: center; | |
border:none; | |
margin:0; | |
padding:0; | |
} | |
a img{ | |
border: 0; | |
max-width: 100%; | |
height: auto; | |
} | |
</style> | |
</head> | |
<body> | |
<a href="<?php echo $nextURL; ?>"><img src="<?php echo $curImg; ?>" /></a> | |
<script type="text/javascript"> | |
document.onkeyup=function(e){ | |
if(e.keyCode == 37){ | |
window.location.replace('<?php echo $prevURL; ?>'); | |
} else if (e.keyCode == 39){ | |
window.location.replace('<?php echo $nextURL; ?>'); | |
} | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment